jmalcolm
asked on
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...
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.
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.
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!
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!
ASKER
Thanks.
Here are 2 interesting side notes:
To get the actual filepath I would need to have...
Application.Options.Defaul tFilePath( wdCurrentF olderPath) & 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...
Here are 2 interesting side notes:
To get the actual filepath I would need to have...
Application.Options.Defaul
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...
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!
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!
As far as I'm aware this should work on any machine that has Word
Dialogs(wdDialogFileOpen).