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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vboukharCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.