FollowHyperLink

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

I use the following to open a word document.

Application.FollowHyperlink "C:\Documents and Settings\Craig\My
Documents\Letter.doc"

This document is for a mail merge.

This works fine on my own computer. If i pass this program on to someone
else, unless their name is the same as mine this is not going to work.

How can I get this to apply to the "User" (without having to edit the code
and change the name for all copies installed)

Thanks
Craig
 
Craig said:
I use the following to open a word document.

Application.FollowHyperlink "C:\Documents and Settings\Craig\My
Documents\Letter.doc"

This document is for a mail merge.

This works fine on my own computer. If i pass this program on to
someone else, unless their name is the same as mine this is not going
to work.

How can I get this to apply to the "User" (without having to edit the
code and change the name for all copies installed)

Thanks
Craig

There may be a simpler way, but I can find two methods. The first is
somewhat fragile, as it relies on the user's OS version having the same
environment strings set up automatically as mine does. The second
involves calling the Windows API to get the path to the "My Documents"
folder. That should be more reliable, but also somewhat more
complicated.

Version 1 -- Trusting Environment Settings
-------------------------------------------

On my Windows 2000 system, this works:

Application.FollowHyperlink _
Environ("homedrive") & Environ("homepath") & _
"\My Documents\Letter.doc"


Version 2 -- Calling the Windows API
---------------------------------------

Go to http://www.mvps.org/access/api/api0054.htm , copy and paste the
code there into a new module in your database. Save the module under
some suitable name -- not the name of any function or procedure. Then
your code to follow the hyperlink can be

Application.FollowHyperlink _
fGetSpecialFolderLocation(CSIDL_PERSONAL) & _
"\Books to read.txt"
 
This may be similar to the 2nd option offered by Dirk, but
for what it's worth, try this;

Application.FollowHyperlink _
"C:\Documents and Settings\" & GetUser _
& "\My Documents\Letter.doc"

You'll need to paste the following into a new module for
it to work;

'*** Start Of Module ***
Option Compare Database
Option Explicit

Declare Function WNetGetUser& Lib "Mpr" _
Alias "WNetGetUserA" (lpName As Any, _
ByVal lpUserName$, lpnLength&)

Function GetUser() As String
On Error Resume Next
Dim UserName As String, cbusername As Long
Dim ret As Long
UserName = Space(256)
cbusername = Len(UserName)
ret = WNetGetUser(ByVal 0&, UserName, cbusername)
If ret = 0 Then
UserName = Left(UserName, _
InStr(UserName, Chr(0)) - 1)
Else
UserName = ""
End If
GetUser = UCase(UserName)
End Function
'*** End Of Module ***
 
Back
Top