Application.GetOpenFilename

W

Win

I am trying to duplicate some Excel code in Word and
cannot find the correct command. Basically, I have a
simple Excel macro that changes the directory and launched
the Open file dialog box and then waits for me to manually
select which file I want to open. Then it opens the file
and ends the macro. I use this macro several times a week
to go to a server where certain files are stored, thus
avoiding always have to manually change the path in the
Open Files dialog box. I started with the Excel code, but
I cannot find the Word equivalent (if there is one) to the
Excel "Application.GetOpenFilename" command. I can make
it work if I name the specific file, but it would be
clumsy to have half a dozen buttons doing the same thing,
only with different file names attached.

Sorry if this is a novice question, but that's what I am
unless the VBA is Excell related. Appreciate any
suggestions. Thanks.
Win
 
M

martinique

Word VBA has a different approach to this. Word has a collection of Dialogs
that includes most (not quite all) of the forms available in the app. The
FileOpen dialog, for example, is

Dialogs(wdDialogFileOpen)

You can .Show the dialog to display it and do whatever the user selects. You
can .Display the dialog to get input from the user without taking any
actions (which I think is what you're looking for here) and you can .Execute
the dialog to take the actions without displaying the form.

Look at "Built-in dialog box argument lists" in Help to see the arguments to
use.
 
W

Win

Thanks Martinque. I used the Dialogs
wdDialogFileOpen).Show suggestion and it works as you
fine. I have one problem left. Before this command I have
the following line:

ChDir "J:\Pricing Group\Portfolio Pricing Strategy\Pricing
Plan"

When the Dialogs wdDialogFileOpen).Show command
executes, it opens to my default directory. The ChDir
code does not error in Word, however, it doesn't seem to
do anything either. I looked up the "Built-in dialog box
argument lists" as you suggested, but I cannot seem to
find one that would solve this and/or get the syntax
correct.

Any suggestions? Thanks.
Win
 
M

martinique

Win said:
Thanks Martinque. I used the Dialogs
wdDialogFileOpen).Show suggestion and it works as you
fine. I have one problem left. Before this command I have
the following line:

ChDir "J:\Pricing Group\Portfolio Pricing Strategy\Pricing
Plan"

When the Dialogs wdDialogFileOpen).Show command
executes, it opens to my default directory. The ChDir
code does not error in Word, however, it doesn't seem to
do anything either. I looked up the "Built-in dialog box
argument lists" as you suggested, but I cannot seem to
find one that would solve this and/or get the syntax
correct.

Any suggestions? Thanks.
Win
 

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