Word XP 2002 returns Illegal Function Call when setting wdUserTemplatesPath

S

src

I've got the strangest problem going on right now in Word 2002. I'm
trying to set the User Templates Path with VBA.

I call a function that gets the UserName. I then insert it into a
string and use that to set the path. Here's a bit of the code:

Options.DefaultFilePath(Path:=wdWorkgroupTemplatesPath) = "V:\Reference
\Templates\"
Options.DefaultFilePath(Path:=wdStartupPath) = "C:\Documents and
Settings\" & GetUserName _
& "\Application Data\Microsoft\Word\STARTUP\"
Options.DefaultFilePath(Path:=wdUserTemplatesPath) = "C:\Documents and
Settings\" _
& GetUserName & "\Application Data\Microsoft\Templates\"

I can successfully run this once. But the next time I run it, I get:
Run-time Error '4101'
Illegal Function Call
on the 3rd line, wdUserTemplatesPath.

I've truncated the string to

Options.DefaultFilePath(Path:=wdUserTemplatesPath) = "C:\Documents and
Settings\" _
& GetUserName & "\Application Data\Microsoft\"

and it works perfectly every time. As soon as I add "Templates\" to
the line, it crashes after the first run.

In Word 2003, this isn't a problem, and both of the other strings
(WorkgroupTemplatesPath and StartupPath) don't have this problem.
I've tried adding "Application." to the Options to no avail, and I've
left the trailing slash off with no effect.

Anyone see this before? Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top