Acquiring filenames for multiple files with GetOpenFilename

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hello from Australia,

I am new to this Newsgroup and fairly new to Excel
programming as well, but the opportunity to talk to such a
newsgroup looks very hopeful indeed.

My problem is in trying to obtain the names of a group of
files and use them in a program.

Using:
fName = Application.GetOpenFilename("DAT files(*.dat),
*.dat", 1, "Select DAT files", , False)

the last parameter, "False", indicates a single selection
and it is stored in "fName", which I can use in a statement
such as: MsgBox "File(s): " & fName
This works ok.

What is the form of the statement for multiple files? i.e.:
fName = Application.GetOpenFilename("DAT files(*.dat),
*.dat", 1, "Select DAT files", , True)

Last parameter is "True". Does "fName" have to be declared
as an array of strings? How can I access all the filenames
from this multiple selection?

Thanks in advance for any help.

John.
 
Hi John,

Good day, from Japan. :-)
The argument for multiple files is as you wrote, TRUE.
And regarding to a variable type, please declare fName As Variant.
When you select multiple files, it can store the file names as an
array.
And you can judge, if the variable fName has value with "VarType" as
follows.


Code:
--------------------

Sub Macro1()
Dim fName As Variant
Dim f As Variant
fName = Application.GetOpenFilename("DAT files(*.dat),*.dat", 1, "Select DAT files", , True)
If VarType(fName) = 11 Then Exit Sub
For Each f In fName
MsgBox Dir(f)
Next
End Sub

--------------------
 
Back
Top