VBA条件格式打印格式

时间:2018-09-13 18:02:18

标签: excel-vba excel-2010

我试图在工作簿中列出所有条件格式设置规则,并在其他地方找到以下代码。该子例程列出了工作表的名称,应用的公式和应用的范围。我有两个问题:

enter image description here

  1. 如何添加额外的一栏以显示格式?

enter image description here

  1. 我是否可以更改Excel选项卡中的规则并将其刷新到条件格式设置规则管理器?如何保留顺序?
Sub List_Conditional_Formatting_Rules()

' Print all conditional formatting rules in the all worksheets
    Application.ScreenUpdating = False

    Dim ws As Worksheet, wsCF As Worksheet, NR As Long
    Dim CFrule As FormatCondition, Rng As range

    On Error Resume Next

    Sheets.Add(After:=Sheets(Sheets.Count)).Name = "CF Rules"   'add sheet
    Set wsCF = Sheets("CF Rules")
    wsCF.range("A1:C1").Value = [{"Sheet","Formula","Range"}]

    NR = 2      'define starting row

    For Each ws In Worksheets
     If ws.Name <> "CF Rules" Then
        Set Rng = ws.Cells

        For Each CFrule In Rng.FormatConditions
            wsCF.range("A" & NR).Value = ws.Name                    ' rule names
            wsCF.range("B" & NR).Value = "'" & CFrule.Formula1      ' formula names
            wsCF.range("C" & NR).Value = CFrule.AppliesTo.Address   ' applied area

            ' want to add a column to show how the format actually looks like

            NR = NR + 1
        Next CFrule
    End If

    Next ws

    wsCF.Columns.AutoFit
    Application.ScreenUpdating = False
    MsgBox ("All conditional formatting rules are printed.")

End Sub

请让我知道我是否可以阅读任何文档以更好地理解这一点。谢谢!

0 个答案:

没有答案