GetOpenFilaName

×

×לי

Hi all!

I am using the Application.GetOpenFilaName procedure in order the get the
path of files. if it is in a MultiSelect mode the pathes are an array. I
tried to copy them to a worksheet but i got only the last path. Is it posible
to get all the pathes each one in a separate cell?

FileName = Application.GetOpenFilename(FileFilter:="Text File
(*.txt),*.txt", MultiSelect:=True)
Range("A1").Value = FileName

Thanks in advance

Eli
 
T

Tim Zych

Here's one way:

Dim Filename As Variant
Filename = Application.GetOpenFilename(FileFilter:="Text File
(*.txt),*.txt", MultiSelect:=True)
If TypeName(Filename) <> "Boolean" Then
Range("A1").Resize(UBound(Filename, 1) - LBound(Filename, 1) + 1).Value
= Application.Transpose(Filename)
End If
 
×

×לי

Thanks a lot Tim

Tim Zych said:
Here's one way:

Dim Filename As Variant
Filename = Application.GetOpenFilename(FileFilter:="Text File
(*.txt),*.txt", MultiSelect:=True)
If TypeName(Filename) <> "Boolean" Then
Range("A1").Resize(UBound(Filename, 1) - LBound(Filename, 1) + 1).Value
= Application.Transpose(Filename)
End If
 
C

Chip Pearson

When the MultiSelect parameter is True, GetOpenFileName returns an
array, even if a single file is selected. First, test the result to
see if it is an array. If it is, then one or more files were selected.
If it is not an array, then the user cancelled the operation. For
example,


Dim FileNames As Variant
Dim N As Long
FileNames = Application.GetOpenFilename( _
filefilter:="Text Files (*.txt),*.txt", _
MultiSelect:=True)
If IsArray(FileNames) Then ' were files selected?
' loop through array of file names
For N = LBound(FileNames) To UBound(FileNames)
Cells(N, 1).Value = FileNames(N)
Next N
Else
' user cancelled the operation
Debug.Print "user cancellled"
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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