ChangeFileOpenDirectory doesn't always work

C

Claudia

We use the following macro code to open our directories:

Sub Open1()
'
ChangeFileOpenDirectory "W:\1\"
Dialogs(wdDialogFileOpen).Show

End Sub

We have a macro just like the above for each folder, i.e. w:\2\, w:\3\, etc.
The problem is running the macro only works if the user does not open a
document. If s/he does open a document, the next time the macro is run, it
simply opens up My Documents. Is there any way that the code can be modified
so that the macros always work, regardless of whether a document was opened?

Claudia Carvalho
 
P

Perry

Try the FileDialog instead, using similar code as examplified below

Dim f As FileDialog
Set f = Application.FileDialog(msoFileDialogOpen)
With f
.InitialFileName = "W:\1\"
If .Show Then .Execute
End With
 
C

Claudia

Thanks, Perry, I'll give that a try. FWIW, I Googled the problem, stumbled on
a solution for a related problem, and that gave me an idea on how to modify
my code. I just copied the string ChangeFileOpenDirectory "W:\1\" and pasted
the results above it. Works great, but I can't explain why. This is the new
code:

ChangeFileOpenDirectory "W:\1\"
ChangeFileOpenDirectory "W:\1\"
Dialogs(wdDialogFileOpen).Show

Claudia Carvalho
 
P

Perry

Great Claudia,

however:
ChangeFileOpenDirectory command can be influenced by other
processes/programs ...
I'd rather control the target directory by imposing it to the dialog ...
like examplified.
 
C

Claudia

Perry said:
however:
ChangeFileOpenDirectory command can be influenced by other
processes/programs ...
I'd rather control the target directory by imposing it to the dialog ...
like examplified.

Thanks, Perry. I discovered later that my code doesn't work consistently,
either. So, I substituted yours and it's working like a champ now! I and 65
other users thank you!

Claudia Carvalho
 

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