Forum Discussion
666_666666
May 25, 2023Copper Contributor
Conditional Formating copy VBA
I can't figure out how to copy conditional formatting rules the task is to copy a rule (not a cell format, but a rule) from, for example, a file.xlsx (not necessarily this type, any format that supp...
HansVogelaar
May 26, 2023MVP
From which sheet and which range in file.xltx do you want to copy the formatting to which sheet and which range in book.xlsm?
666_666666
May 26, 2023Copper Contributor
From what sheet
1st
and in what range
is all
in the file.xlsx do you want to copy
formatting to which sheet
1st
and in what range
is all
in book.xlsm?
in .xltx I have a rule that applies to the entire sheet
XML code from .xltx
...
- <conditionalFormatting sqref="A1:XFD1048576">
- <cfRule priority="1" dxfId="0" type="expression">
<formula>xxx</formula>
</cfRule>
</conditionalFormatting>
...
- HansVogelaarMay 26, 2023MVP
The macro could look like this:
Sub CopyFormatting() Workbooks("file.xltx").Worksheets(1).Cells.Copy Workbooks("book.xlsm").Worksheets(1).Cells.PasteSpecial Paste:=xlPasteFormats End Sub- 666_666666May 26, 2023Copper ContributorRun-time error #("RTE" on next)
Class not registered
When add paths
Without paths
RTE 9
Subscript out of range
if I use the names of windows
it works
thank you, at least I understood that I should try to test for search
New question
how to get the names of windows,
the active document, and the template that opened later
, the fact is that excel changes the name of the window to another one... the template file is 0.xltx and the window is called 01 (without extension)- HansVogelaarMay 26, 2023MVP
If the .xlsm file is the one that contains the macro, and the file created from the template is the active workbook when you run the macro:
Sub CopyFormatting() ActiveWorkbook.Worksheets(1).Cells.Copy ThisWorkbook.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteFormats End Sub