Hi, thanks for your help.
I'm using Word XP. I have one line of code that works:
Options.DefaultFilePath(Path:=wdWorkgroupTemplatesPath) = "C:\Program
Files\Microsoft Office\Templates\IRTemplates"
and one that does not work:
Options.DefaultFilePath(Path:=wdUserTemplatesPath) =
"%Userprofile%\application data\microsoft\Templates"
I've checked the paths and all the folders are there. Is there any reason
why %Userprofile% shouldn't work? Thanks for your help
>Hi, thanks for your help.
>
[quoted text clipped - 10 lines]
>I've checked the paths and all the folders are there. Is there any reason
>why %Userprofile% shouldn't work? Thanks for your help
Why should it work? First, variables delimited by % signs in batch
files refer to environment variables, and there isn't any such
environment variable in a default Windows installation. Second, VBA
doesn't interpret the % signs the way batch files do. It just isn't
supported in VBA.
Instead, you can include the following function in your template. It
uses the PrivateProfileString function to extract the needed
information from the registry.
Function UserProfile() As String
Const RegPath = "HKEY_CURRENT_USER\Volatile Environment"
Dim HomeDrive As String, HomePath As String
HomeDrive = System.PrivateProfileString("", _
RegPath, "HOMEDRIVE")
HomePath = System.PrivateProfileString("", _
RegPath, "HOMEPATH")
UserProfile = HomeDrive & HomePath
End Function
You could use it like this:
Options.DefaultFilePath(Path:=wdUserTemplatesPath) = _
Userprofile & "\application data\microsoft\Templates"
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Jay Freedman - 14 Sep 2005 15:04 GMT
>> Hi, thanks for your help.
>>
[quoted text clipped - 36 lines]
> Options.DefaultFilePath(Path:=wdUserTemplatesPath) = _
> Userprofile & "\application data\microsoft\Templates"
Now that I've had a chance to look at a system in a networked environment,
that function may not return the correct path, depending on how the login
script is written. Use this one instead:
Function UserProfile() As String
Const RegPath = "HKEY_CURRENT_USER\Volatile Environment"
UserProfile = System.PrivateProfileString("", _
RegPath, "APPDATA")
End Function
and then change the calling routine to use this:
Options.DefaultFilePath(Path:=wdUserTemplatesPath) = _
Userprofile & "\Microsoft\Templates"

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org