Macro to return filepath and name from browse window

P

PaxDak

I'm new to VBA in Word. In Excel, I would use Application.GetOpenFileName
to bring up a browser window to allow the user to browse for a specific
file, and then return the selected file as a string.

Is there something equivalent in Word?

I saw the Copy File dialog on the MVP site:
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
MsgBox "You chose " & .Directory
Else
MsgBox "Dialog cancelled"
End If
End With

Which returns just the folder path. Looking for the same thing that returns
the file name also. Would also like to set what the the default folder path
is (i.e. the default folder that the browse window opens in).

Any help would be appreciated.

-Pax
 
D

Doug Robbins - Word MVP

Hi Pax,

Use the following construction

With Dialogs(wdDialogInsertPicture)
If .Display Then
'Populate the txtLargeLogoPath control with the selected
filename
txtLargeLogoPath = WordBasic.FilenameInfo$(.Name, 1)
End If
End With

Changing the dialog to the one that you want to use

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Cindy M -WordMVP-

Hi PaxDak,
I'm new to VBA in Word. In Excel, I would use Application.GetOpenFileName
to bring up a browser window to allow the user to browse for a specific
file, and then return the selected file as a string.

Is there something equivalent in Word?
Which version of Word? If it's 2002 or above there's a new FileDialog object
in OFFICE that will let you do this quite handily. You can set filters,
change the button and title bar names...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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