Get a file name

From my macro I want to launch a dialog box which prompts the user to find an .xml file. I want a common dialog but I can't use the comdlg32.ocx because I'm distributing to machines that don't have this vb control.  I need to invoke an open dialog that is going to work on any Word97 machine. I know there must be an easy way to do this. I know there is in Excel, there is a GetFilename of something like that which invokes a common Open dialog, but I can't find anything on the Word odbject model that does anything like this. Please help! There must be a simple way to invoke a Common Open dialog from Word...
jmalcolmAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vboukharConnect With a Mentor Commented:
OK, look at solution below - it works
Sub GetXml()
With Dialogs(wdDialogFileOpen)
 .Name = "*.xml"
 .Display
 tmpStr = .Name
End With
MsgBox tmpStr
End Sub

Hope it's an answer indeed :-)
0
 
antratCommented:
Hi jmalcolm

As far as I'm aware this should work on any machine that has Word
Dialogs(wdDialogFileOpen).Show

0
 
vboukharCommented:
Just as an addition to antrat comment: to find *.xml file
Sub GetXlm()
With Dialogs(wdDialogFileOpen)
 .Name = "*.xml"
 .Show
End With
End Sub

P.S. I can't find a way to change "File type" combo to display proper file format.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jmalcolmAuthor Commented:
Those Open a file as a word Document, actually creating a new Document.  I simply want to get a filepath( as a string), I don't want it to open a document.  With the Dialogs(wdDialogOpen) there is the .Display method which is suppose to just display the dialog and not perform the function, but I am unable to get any return values from the dialog using this method. The .Name property doesn't contain anything when I select a file.  Are there other properties like .Name that aren't referenced in the documentation?
0
 
vboukharCommented:
Or another way (with creation of your own instance of Dialog)
Sub GetXml2()
 Dim r As Dialog
 Set r = Dialogs(wdDialogFileOpen)
 r.Name = "*.xml"
 r.Display
 MsgBox r.Name
End Sub
 
Now it hold changes, made by user. When you wrote "The .Name property doesn't contain anything when I select a file." I guess, you try to read  .Name property of new instance of Dialogs(wdDialogFileOpen) - the instance of dialog, where user has selected file, was distroyed after With..End With statement end.
...it's no easy for me to explain something in English!
0
 
jmalcolmAuthor Commented:
Thanks.
Here are 2 interesting side notes:

To get the actual filepath I would need to have...

Application.Options.DefaultFilePath(wdCurrentFolderPath) & r.Name

Also, to get a list of all the built in parameters for the dialogs
search the Microsoft Word Visual Basic Reference Help index for "Built-in dialog box argument lists."

Kinda cool..

Thanks again...
0
 
vboukharCommented:
Thank for points, jmalcolm, but it seems you have answered by yourself. I show the way to get filename instead of filepath - I understood you initial question in this way and don't read carefully you further comments. :-(
If you need any extra help in MSOffice products, I can try to solve it 'free' - just post it in this question. Maybe it help  you to save some points for future.
Good luck!
0
All Courses

From novice to tech pro — start learning today.