RE: Open a Folder Using VBA



Steve,

There are probably a multitude of ways to accomplish what you want, but one
of the easiest is something like this:

Sub OpenFolder()
ChangeFileOpenDirectory "z:\word\"
Dialogs(wdDialogFileOpen).Show
End Sub

It's a bit sloppy in that it changes the "file open directory" without
warning the user, and of course, this change will stick until the next time
Word is restarted. However, this isn't much different from what Word does
natively - as you discovered when you said "it opens the last
directory/folder that used in Word".

Other methods are available, and there are ways to work around the
limitation of the above; e.g. recording the current "file open directory" in
a variable and resetting it afterwards. However, these methods might be a bit
more complicated and probably not worth the effort for a limited application.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


"Steve" wrote:

I’m trying to write a macro that will do the same thing as File/Open but it
will open the “file listing dialog box” to a particular folder (e.g.,
z:\word) and then allow me to choose which file to open in that
folder/directory.

When I record the macro, I get to the open dialog box for the desired
folder, but I’m unable to turnoff the recorder at the desired folder. I can
either cancel the recording or continue until I select a document. I would
like the macro to stop at the desired folder and allow the use to select the
document to open.

In doing some research, it seems that I need to write a VBA code to
accomplish the task. I have a very limited knowledge base when it comes to
writing code.

I did find the following code:

Sub OpenFolder()
Application.Dialogs(wdDialogFileOpen).Show
End Sub

It does works; but it opens the last directory/folder that used in Word.

What additional code/lines do I need to include so it opens to the
directory/folder z:\word?

At this point, I’m not even sure if I’m asking the question correctly. Any
help or suggestions are appreciated.
.



Relevant Pages

  • Re: wdDialogFileSaveAs wont accept filename variable
    ... ChangeFileOpenDirectory "C:\" ... which will change the file open path. ... Using that code the correct folder is opened and the only thing the user ... in Word2000 the dialog box opens to ...
    (microsoft.public.word.vba.beginners)
  • Re: Word 2003: Need macro to stop redirecting where to find a file
    ... Dim sPath As String ... Here is an example of the macro that opens a ... how does the macro know in what directory ... ChangeFileOpenDirectory changes the.....file open directory. ...
    (microsoft.public.word.vba.general)
  • Open a Folder Using VBA
    ... When I record the macro, I get to the open dialog box for the desired ... but I’m unable to turnoff the recorder at the desired folder. ... but it opens the last directory/folder that used in Word. ...
    (microsoft.public.word.vba.general)
  • RE: Opening a file from a set folder
    ... Well that proved to be easily done by ChDir. ... > I need to open files from folders x, ... When the file dialog opens it ... > So how can I set the file dialog box to open from the desired folder. ...
    (microsoft.public.excel.programming)
  • Opening a file from a set folder
    ... I need to open files from folders x, ... When the file dialog opens it ... either displayes the default path or the last used. ... So how can I set the file dialog box to open from the desired folder. ...
    (microsoft.public.excel.programming)