Re: Merging excel workbooks
Use the Sheets collection to get the number of sheets in the workbook. Then to refer to the workbook or sheet without hard coding the names, use their index numbers instead.
Re: Merging excel workbooks
But I want to retain the sheet's name in the destination workbook.
Re: Merging excel workbooks
This will copy all of the sheets, including all formatting, headers, page setup, etc. from a source workbook into a destination workbook:
Code:
'This will append all sheets from the "bBook" after the last sheet of the "aBook"
Call Macro1(bBook, aBook)
Sub Macro1(ByRef wbkSrc As Workbook, ByRef wbkDst As Workbook)
Dim aSheet As Worksheet
For Each aSheet In wbkSrc.Sheets
aSheet.Copy after:=wbkDst.Sheets(wbkDst.Sheets.Count)
Next aSheet
End Sub