Hi
Here is one way..
Code:
Function GetFileList(FileSpec As String) As Variant
'Where FileSpec = PathToFiles & "\*.csv"
Dim i As Long
Dim Fldr As String
Dim Extn As String
Dim fl, f(), j As Long
Dim wbk As Workbook
Fldr = Left$(FileSpec, InStrRev(FileSpec, "\"))
Extn = Replace(FileSpec, Fldr, vbNullString)
With CreateObject("scripting.filesystemobject").getfolder(Fldr)
ReDim f(1 To .Files.Count, 1 To 2)
For Each fl In .Files
If fl.Name Like Extn Then
i = i + 1
f(i, 1) = fl.Name
f(i, 2) = fl.DateLastModified
End If
Next
Set wbk = Workbooks.Add
With wbk.Worksheets(1)
.[a1].Resize(UBound(f, 1), 2) = f
.[a1].Resize(UBound(f, 1), 2).Sort .Cells(1, 2), 1
GetFileList = .[a1].Resize(UBound(f, 1))
End With
wbk.Close 0: Set wbk = Nothing
End With
End Function
Bookmarks