Conditional Formatting changes from XLSM to XLSX when I use VBA code to save a new file

Stevep4

New Member
Joined
Aug 28, 2015
Messages
35
I have the below code that takes two worksheets in an xlsm workbook and it saves them as an xlsx workbook. The problem is that when the two sheets are saved into an new xlsx workbook the conditional formatting colors change. Is there a way to keep the formatting from XLSM to XLSX?


VBA Code:
Sub SaveCopyAs_Without_MacrosStore()
ThisFile = Sheets("Summary").Range("d11:d11").Value
Sheets(Array("LW-MTD-YTD", "By Week")).Copy
ActiveWorkbook.SaveAs Filename:="S:\Merch Analysis\ALL REPORTS\Monday Reporting\SenSource\Archive\" & ThisFile & ".xlsx", FileFormat:=51
Set Wkb = Workbooks.Open("S:\Merch Analysis\ALL REPORTS\Monday Reporting\SenSource\Archive\" & ThisFile & ".xlsx")
Wkb.Close Savechanges:=True
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi Stevep4,

Are you still looking for solution?

There might be a few color RGB in the Theme need to be copied. I added this loop before closing the new workbook. Refer below.

Try this code:
VBA Code:
Sub SaveCopyAs_Without_MacrosStore()
ThisFile = Sheets("Summary").Range("d11:d11").Value
Sheets(Array("LW-MTD-YTD", "By Week")).Copy
ActiveWorkbook.SaveAs Filename:="S:\Merch Analysis\ALL REPORTS\Monday Reporting\SenSource\Archive\" & ThisFile & ".xlsx", FileFormat:=51
Set Wkb = Workbooks.Open("S:\Merch Analysis\ALL REPORTS\Monday Reporting\SenSource\Archive\" & ThisFile & ".xlsx")

For i = 1 To ThisWorkbook.Theme.ThemeColorScheme.Count
Wkb.Theme.ThemeColorScheme.Colors(i).RGB = ThisWorkbook.Theme.ThemeColorScheme.Colors(i).RGB
Next i

Wkb.Close Savechanges:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,635
Messages
6,125,940
Members
449,275
Latest member
jacob_mcbride

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top