Collect Excel Files From A folder

     

    How to collect only excel files in a Directory\Folder:

     

    Private Sub CommandButton1_Click()
    Dim source As String
    source = "D:\Consolidation\"
    Dim filename As String
    filename = Dir(source & "*.x??")
    'Extensions:
    '(i) .xls for workbook without macros upto 2003
    '(ii) .xlsx for workbook without macros from 2007
    '(ii) .xlsm for workbook withmacros
    Dim e As Integer
    Do While filename <> ""
    e = e + 1
    Cells(e, 1) = filename
    filename = Dir
    Loop
    Cells.EntireColumn.AutoFit
    End Sub

     

    Download the folder and copy in "D" drive before executing the query

     

    Download The Workbook