Sub CollectSheetsFromFolder()
' --> Settings, change to suit
Const MASK = "April*"
Const Folder = "D:\MyFolder"
'<-- End of setings
Dim Arr()
Dim i As Long, j As Long
Dim wb As Workbook
Dim Sh As Worksheet
Dim FileName As String
' Create new workbook with single empty sheet
Set wb = Workbooks.Add(xlWBATWorksheet)
' Trap errors
'On Error GoTo exit_ '<-- This should be commented for the debugging
' Main - collect all MASK like sheets from workbooks in Folder
Application.ScreenUpdating = False
FileName = Dir(Folder & "\*.xls*")
Do While FileName <> ""
Debug.Print Folder & "\" & FileName
With Workbooks.Open(Folder & "\" & FileName, ReadOnly:=True)
i = 0
ReDim Arr(1 To .Sheets.Count)
For Each Sh In .Worksheets
If UCase(Sh.Name) Like UCase(MASK) Then
i = i + 1
j = j + 1
Arr(i) = Sh.Name
End If
Next
If i > 0 Then
ReDim Preserve Arr(1 To i)
Sheets(Arr).Copy After:=wb.Sheets(wb.Sheets.Count)
End If
.Close False
End With
FileName = Dir()
Loop
' Delete the 1st extra sheet
If wb.Sheets.Count > 1 Then
Application.DisplayAlerts = False
wb.Sheets(1).Delete
Application.DisplayAlerts = True
End If
exit_:
Application.ScreenUpdating = True
If Err Then
MsgBox Err.Description, vbCritical, "Error"
ElseIf j > 0 Then
MsgBox "New workbook with " & j & " collected sheet" & IIf(j > 1, "s", "") _
& " like '" & MASK & "' is created", vbInformation, "Done"
ElseIf j = 0 Then
MsgBox "No '" & MASK & "' sheets found", vbExclamation, Folder
End If
End Sub