Read the filename from the wdDialigsFileOpen dialog?

A

and

Dear all,

Does anyone know how to read the filename the user selects in the
default FileOpen dialog, into a variable?

I've tried this (in vain):

=================
Dim dlgA as Dialog
Set dlgA = Dialogs(wdDialogFileOpen)

With dlgA
.Show
varB = .Name
End With
=================

TIA,
AND
 
A

and

I should add that I don't want to open the file, so I will use Display
in stead of Show. And also, I want the file name plus the full path to
it as a result.



-------- Original Message --------
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

To get just the name of the selected file, use

Dim docname As String
With Dialogs(wdDialogFileOpen)
If .Display Then
docname = .Name
End If
End With
MsgBox docname

To get the path and the name, use

Dim docname As String
With Dialogs(wdDialogFileOpen)
If .Display Then
docname = WordBasic.FilenameInfo$(.Name, 1)
End If
End With
MsgBox docname


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
A

and

Hi Doug,

I guess this does the same (someone else's contribution off this list):

Dim dlgA As FileDialog
Set dlgA = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtItem As Variant
With dlgA
.AllowMultiSelect = False
If .Show = -1 Then
For Each vrtItem In .SelectedItems
MsgBox vrtItem
Next vrtItem
Else
End If
End With
Set dlgA = Nothing


but is there any reason why one should prefer this solution to the one
you mention?

Kind regards,
AND
-------- Quote From the Original Message --------


[...]
 
J

Jean-Guy Marcil

Hi and,

One difference is that with msoFileDialogFilePicker you could ask a user to
select many files by changing
.AllowMultiSelect = False
to
.AllowMultiSelect = True

and thus build an array with all the file names selected by the user.

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


and said:
Hi Doug,

I guess this does the same (someone else's contribution off this list):

Dim dlgA As FileDialog
Set dlgA = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtItem As Variant
With dlgA
.AllowMultiSelect = False
If .Show = -1 Then
For Each vrtItem In .SelectedItems
MsgBox vrtItem
Next vrtItem
Else
End If
End With
Set dlgA = Nothing


but is there any reason why one should prefer this solution to the one
you mention?

Kind regards,
AND
-------- Quote From the Original Message --------


[...]
To get the path and the name, use

Dim docname As String
With Dialogs(wdDialogFileOpen)
If .Display Then
docname = WordBasic.FilenameInfo$(.Name, 1)
End If
End With
MsgBox docname
 
A

and

Hi Jean-Guy,

But are both methods compatible with Word 97, Word 2000 and Word XP
(version 8, 9 and 10)?
 
J

Jonathan West

and said:
Hi Jean-Guy,

But are both methods compatible with Word 97, Word 2000 and Word XP
(version 8, 9 and 10)?

No. The Filepicker dialog was introduced in XP and is not supported in
earlier versions of Word.
 

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