wakerider017
Board Regular
- Joined
- Jun 10, 2015
- Messages
- 77
I have multiple workbooks saved in C:\Temp.
They look like:
Below is my current VBA. I am able to search for prefix "AAAA" and that creates a new master file with all tabs from AAAA_1, AAAA_2 and AAAA_3, but then how to I start over (automatically) and create master files for all of the other prefixes that exist in C:\Temp? Thanks from a VBA rookie!
They look like:
- AAAA_1.xlsx
- AAAA_2.xlsx
- AAAA_3.xlsx
- BBBB_1.xksx
- BBBB_2.xksx
- CCCC_1.xlsx
- CCCC_2.xlsx
- CCCC_3.xlsx
- CCCC_4.xlsx
- etc.
Below is my current VBA. I am able to search for prefix "AAAA" and that creates a new master file with all tabs from AAAA_1, AAAA_2 and AAAA_3, but then how to I start over (automatically) and create master files for all of the other prefixes that exist in C:\Temp? Thanks from a VBA rookie!
VBA Code:
Sub Merge()
Path = "C:\Temp\"
Filename = Dir(Path & "AAAA" & "*.xlsx")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Application.DisplayAlerts = False
Workbooks(Filename).Close
Filename = Dir()
'Save workbook
Loop
Application.DisplayAlerts = True
ActiveWorkbook.SaveAs Filename:="C:\Temp\File_" & Range("A1") & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
End Sub