how do i get a filepath from fileopen dlg in Word (or Excel)

S

spiffo

ok, I have 3 books on VBA, and NONE of them address this! (AGHHHH!!!!)

they show this fine manuever...:

Application.Dialogs(wdDialogFileOpen).Show

Works great if you want the user to be able to open a doc... but I just need
the file name... i can do this,

Application.Dialogs(wdDialogFileOpen).Display

which just displays the dialog without actually opening it on OK... but then
how the heck do I get the name of the file they selected??? I tried

Application.Dialogs(wdDialogFileOpen).FileName with no luck...

Help pls!!!

thx
 
K

Karl E. Peterson

spiffo said:
Works great if you want the user to be able to open a doc... but I
just need the file name... i can do this,

Application.Dialogs(wdDialogFileOpen).Display

which just displays the dialog without actually opening it on OK...
but then how the heck do I get the name of the file they selected???
I tried

Application.Dialogs(wdDialogFileOpen).FileName with no luck...

Found this:

' To get the name without opening the document
With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
strDoctoUse = .Name
End If
End With

As the first hit with this:

http://www.google.com/search?q=wdDialogFileOpen

Later... Karl
 
J

Jonathan West

Karl E. Peterson said:
Found this:

' To get the name without opening the document
With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
strDoctoUse = .Name
End If
End With


If you want the full pathname, modify the above as follows

' To get the name without opening the document
With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
strDoctoUse = WordBasic.FileNameInfo$(.Name, 1)
End If
End With

It is different in Excel. For that, use the GetOpenFilename method instead.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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