I have a couple of SSRS reports (.xls files) with different Structures:
- Report 1 has 3 excel sheets inside it.
- Report 2 has 2 excel sheets inside it.
- Report 3 has 4 excel sheets inside it.
I want all these 9 excel sheets to be merged into single Excel file having different sheets, that is, my final excel file should have all these 9 sheets where I am able to achieve using the below macro code.
Path = "C:\Users\FILES\" ' This will fetch all the files form the mentioned location
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
Application.DisplayAlerts = False ' Delete an extra sheet
Worksheets("SHEET1").Delete
Application.DisplayAlerts = True
Application.DisplayAlerts = False ' This will create a new excel file and stores all the data in to it.
ThisWorkbook.CheckCompatibility = False
ThisWorkbook.SaveAs Filename:="C:\Users\merge.xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
Application.DisplayAlerts = False ' Save and exit
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.Quit
The only problem I am facing is while merging the files my VBA code excluding the colors applied to a few cells in my SSRS reports.
How can I copy the excel files without losing the color format already applied?