Word 2003: Need macro to stop redirecting where to find a file

K

Kathryn Pundt

I create a macro, a simple one to open a file from a directory. If I happen
to run another macro that finds a file from a different directory, other
macros are redirected to a wrong directory. No matter how many times I
recreate the macro, the path is removed from the macro after I run a
different macro. Most of my macros are simply to open a file. I have put
them in a pulldown menu on my toolbar. How can I make my macros remain as I
have created them?
 
F

fumei via OfficeKB.com

I suspect you are using ChangeFileOpenDirectory. Stop doing that, if
possible. If you are opening an explicit file, there is no need to alter
ChangeFileOpenDirectory. Just open the file by its path.

ChangeFileOpenDirectory changes the.....file open directory. It remains
whatever you set it at, until you set it for something else.

Either that, and this is a good "best practice", when you change something,
at the end of your procedure, change it back.
 
K

Kathryn Pundt

So, I would type in the macro:

Documents.Open FileName:="""00 - Prosecution Instructions.doc""", _

or

"Y:\Kathryn\INSTRUCT - Prosecution\"
Documents.Open FileName:="""00 - Prosecution Instructions.doc""", _
 
G

Graham Mayor

What you require (based on your earlier message) is presumably

Dim sPath As String
sPath = "Y:\Kathryn\INSTRUCT - Prosecution\"
Documents.Open FileName:=sPath & "Invoice template.doc"

ie include the path (here sPath) in the file open statement. Word always
retains the focus of the last used folder, so you need to include the path
in the open statement.

Also if as the filename suggests, this is a template, you may be better
saving it as a template and using file > new to open documents from it. eg

Dim sPath As String
sPath = Application.Options.DefaultFilePath(wdUserTemplatesPath) & "\"
Documents.Add Template:= _
sPath & "Invoice Template.dot", NewTemplate:=False


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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