Get a list of files in VBA
There are two ways to get a list of files inside a folder with VBA. The first one is the Microsoft Scripting Library way, where the FileSystemObject is used. The second one is the "traditional" Dir command which returns a file each time the function is called. 'the scripting lib way Public Function GetListOfFiles(path As String, ParamArray Extensions()) As String() Dim fs As New FileSystemObject Dim fld As Folder: Set fld = fs.GetFolder(path) Dim fl As file Dim list() As String, count As Long: count = 0 For Each fl In fld.files Dim ext As String, extIncluded As Boolean, i As Long ext = fs.GetExtensionName(fl.name) extIncluded = False For i = 0 To UBound(Extensions) If LCase(ext) = LCase(Extensions(i)) Then extIncluded = True Exit For End If Next 'If ext = "xls" Or ext = "xlsb" Or ext = "xlsx" Or ext = "xlsm" Then ...