File Open

R

Ricki Miles

I am using Word 2003 and would like to create a macro that goes to File,
Open and navigates to a certain folder. Once it gets to that folder, the
macro stops. I know I am missing the last line of code to accomplish this.

TIA,

Ricki
 
J

Jay Freedman

I am using Word 2003 and would like to create a macro that goes to File,
Open and navigates to a certain folder. Once it gets to that folder, the
macro stops. I know I am missing the last line of code to accomplish this.

TIA,

Ricki

You're thinking in terms of what you would do if you were operating
Word with the keyboard and mouse. VBA doesn't work that way.

The VBA way is to create an object that represents the dialog, then
set its properties so it will do what you want, and finally start it
running. In this case, the property of interest is called .Name, and
it represents the contents of the Filename box in the dialog. If you
set that property to the complete folder path and end it with a
backslash instead of a filename, the dialog will immediately open with
that folder visible:

Sub demo()
Dim dlg As Dialog
Set dlg = Dialogs(wdDialogFileOpen)

With dlg
.Name = "C:\Some folder\Some subfolder\"
.Show
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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