Question : How do I return multiple files in Excel VBA using GetOpenFilename?

Hi

I have the following line of code in an Excel VBA macro:

sFile = Application.GetOpenFilename("Excel files,*.xls", MultiSelect:=True)

I found the multiselect trick from another Experts listing, and it does indeed allow me to select multiple files, but I'm not sure how to retrieve the results. The line above just doesn't work as it obviously needs an array but I don't know how to put that into code!

I need to run through the list of filenames selected and add them to a list box. The code should also be able to cope with the user selecting just one file.

How can I achieve this ?

Thanks in advance
DC

Answer : How do I return multiple files in Excel VBA using GetOpenFilename?

Here is how you would loop through the array returned by the GetOpenFilename - multiselect statement

Sub Test()
    Dim sFile As Variant
    Dim i As Long

    sFile = Application.GetOpenFilename("Excel files,*.xls", MultiSelect:=True)
    For i = LBound(sFile) To UBound(sFile)
        Debug.Print sFile(i)
    Next i

End Sub
Random Solutions  
 
programming4us programming4us