Hello Welchs101,
The array passed back the function is a Variant that contains strings. If there are no files found then the return value will be "empty". The returned array is a 1-D array.
Here is an example of listing the returned files in column "A" of the active sheet:
Dim ExcelFiles As Variant
Dim Rng As Range
If Not IsEmpty(ExcelFiles) Then
Set Rng = Range("A1").Resize(RowSize:=UBound(ExcelFiles))
Rng.Value = WorksheetFunction.Transpose(ExcelFiles)
End If
Updated Macro
Function ReturnFileList() As Variant
Dim Cnt As Long
Dim ExcelFiles() As Variant
Dim FilePath As String
Dim FileName As String
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
Set oFolder = objShell.BrowseForFolder(0, "Pick a Folder to Open", 0)
If oFolder Is Nothing Then Exit Function
FilePath = oFolder.Self.Path & "\"
FileName = Dir(FilePath & "*.xls")
If FileName = "" Then
MsgBox "No Excel Files were Found in this Folder.", vbCritical
Exit Function
End If
Do While FileName <> ""
Cnt = Cnt + 1
ReDim Preserve ExcelFiles(Cnt)
ExcelFiles(Cnt) = FileName
FileName = Dir()
Loop
ReturnFileList = ExcelFiles
End Function
Bookmarks