Missing FilePicker Dialog

G

GPL

I had been using the FileDialog object in a Word (2002)
add-in until a colleague running Word 2000 tried to use
it and got an error. I discovered that the FileDialog
object is available only in the Office 10.0 library.
Since I need to distribute this add-in to people whose
version of Office I won't be able to update, I want to do
without using the FileDialog object. But I can't seem to
find a filepicker type dialog otherwise. Does one exist?
Or will I need to create my own filepicker using a
userform?

I should note that I considered using Word's built-in
fileopen dialog as a workaround. But I don't need to open
the file that is picked. (The program simply needs to
take the fullname of the document that is picked and
assign that value to one of the activedocument's
variables.) I'd prefer to avoid that workaround if
possible.

Thanks for any guidance,
GPL
 
J

Jonathan West

If all you want is to know the name of the file that was selected, the
following routine returns the full pathname of the selected file, or returns
a blank string if the user cancels.

Function GetOpenFileName(ByVal Folder As String, ByVal FileType As String)
As String
If InStr(Folder, " ") > 0 Then Folder = """" & Folder & """"
If Len(Folder) > 0 Then
Options.DefaultFilePath(wdDocumentsPath) = Folder
End If
With Dialogs(wdDialogFileOpen)
.Name = FileType
If .Display = -1 Then
GetOpenFileName = WordBasic.FileNameInfo$(.Name, 1)
End If
End With
End Function

the key to this (as well as using other built-in dialogs) is that you use
the Display method rather than the Show method to call the dialog. The
Display method does not take the actions (such as opening the selected file)
that you would expect from displaying the dialog manually.

If you are writing macros that will need to be supported in multiple
versions of Word, it is generally less troublesome to write using the oldets
version you will have to support, and then test in more recent versions.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


The function allows you to preselect the folder in which the dialog opens,
and
 

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