default filepath in XP

S

src

I've got this same problem and I can't figure it out.

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.

Any ideas?
Thanks

|| In Word 2k, the following code successfully "set" the default
filepath:
|| Options.DefaultFilePath(Path:=wdUserTemplatesPath)="C:
\Documents and
|| Settings\username\Application Data\Microsoft\Templates"
||
|| Now, in Word XP, this code results in an error:
|| Run-time error 4101
|| Illegal function call
||
|| If I use the macro recorder, to "set" the same path, I am
unsuccessful
|| (won't let me select this folder), but if I use the macro recorder
to
"set"
|| the path to "C:\" , I am successful, and then g0don't get the error
on
|| running the sub. Is there some different kind of permissions
structure
for
|| XP files for my chosen filepath in XP, or else what's the deal,
guys?
||

Works OK here (I pasted your code in a Word XP module).
Are you sure you did not forget to change "username" for the actual
name?
Just checking... you never know! I have done much dumber mistakes!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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