I have files named "A0118", "A0218"..."A1208". Each file has different number of sheets but they have same names. e.g. "A0118" has worksheets names "1", "2", "3", "X" "Y"; "A1218" has worksheets "1", "3", "Y".
I want to copy all the worksheets from each file into a new workbook and have the names of the worksheet include the name of the file so for file "A0118" i want the copied sheets to be named "0118 - 1" so add "0118 - " in front of the original sheet name.
I'm not sure how to amend the copied worksheet and I'm stuck at this line
ActiveSheet.Name = "0118 - " &
Any help would be much appriciated. Thanks Any advice on improving the existing code is also appriciated!
Sub XYZ()
Application.ScreenUpdating = False
Dim sh As Worksheet
Workbooks.Open Filename:="C:\Users\CopyHere.xlsx"
Set b1 = ActiveWorkbook
Workbooks.Open Filename:="C:\Users\A0118.xlsx", Password:="1", writeresPassword:="1"
Set b2 = ActiveWorkbook
For Each sh In b2.Sheets
sh.Copy After:=b1.Sheets(b1.Sheets.Count)
ActiveSheet.Name = "0118 - " &
Next sh
Workbooks("A0118.xlsx").Close
'
'
'
Workbooks.Open Filename:="C:\Users\A1218.xls", Password:="1", writeresPassword:="1"
Set b13 = ActiveWorkbook
For Each sh In b13.Sheets
sh.Copy After:=b1.Sheets(b1.Sheets.Count)
ActiveSheet.Name = "1218 - " &
Next sh
Workbooks("A1218.xlsx").Close
Application.ScreenUpdating = True
End Sub