4

我得到了一张纸,我正在尝试匹配他们选择的非常深的蓝色。

当我单击主页条中“填充图标”旁边的三角形以调出颜色选择器时,我可以看到颜色是第三列中倒数第二个,蓝色。它被称为“深蓝色,文本 2,深 25%”。

为了清楚起见,我想在 VBA 中执行此操作并使用英文术语。我尝试了各种列出 VBA 颜色名称的网页,但它不存在。有没有办法在不诉诸数字 RGB 或类似的情况下选择它?

4

3 回答 3

2

检查此项以查看样式的颜色:

Sub TestMe()

    Dim st As Style
    Dim cnt As Long: cnt = 1

    For Each st In ThisWorkbook.Styles
        Cells(cnt, 1).Interior.ColorIndex = cnt
        Cells(cnt, 2) = cnt
        Cells(cnt, 3) = st.Name
        Cells(cnt, 4) = st.NameLocal
        cnt = cnt + 1
    Next st

End Sub

返回这个:

在此处输入图像描述

如果您想对特定选择使用特定样式:

selection.interior.colorindex = ThisWorkbook.Styles("40 % - Akzent3").Interior.ColorIndex
于 2018-05-23T15:23:25.130 回答
2

我认为您必须使用以下属性:

   .ThemeColor = xlThemeColorAccent5 'name of the theme
   .TintAndShade = 0.25 'darkness (1 - no dark; -1 - max dark)
于 2018-05-23T15:40:44.253 回答
1
Sub DemoThemecolors()
   Dim rng As Range
   Dim n As Integer, m As Integer
   Dim arrNames
   Dim arrDescriptions
   Dim arrValues
   arrNames = Array("xlThemeColorAccent1", "xlThemeColorAccent2", "xlThemeColorAccent3", "xlThemeColorAccent4", "xlThemeColorAccent5", "xlThemeColorAccent6", _
                    "xlThemeColorDark1", "xlThemeColorDark2", "xlThemeColorFollowedHyperlink", "xlThemeColorHyperlink", "xlThemeColorLight1", "xlThemeColorLight2")
   arrDescriptions = Array("Accent1", "Accent2", "Accent3", "Accent4", "Accent5", "Accent6", "Dark1", "Dark2", "Followed hyperlink", "Hyperlink", "Light1", "Light2")
   arrValues = Array(5, 6, 7, 8, 9, 10, 1, 3, 12, 11, 2, 4)

   ActiveWorkbook.Worksheets.Add
   Set rng = Cells(2, 7)
   rng(0, 4).Value = "TintAndShade"
   rng(1, 4).Value = 0
   For m = 1 To 9
      rng(1, m + 4).Value = 0.1 * m
   Next m
   rng(1, 1) = "ThemeColor Name"
   rng(1, 2).Value = "Value"
   rng(1, 3).Value = "Description"

   For n = 1 To 12
      rng(n + 1, 1).Value = arrNames(n)
      rng(n + 1, 2).Value = arrValues(n)
      rng(n + 1, 3).Value = arrDescriptions(n)
      rng(n + 1, 4).Interior.ThemeColor = arrValues(n)
      For m = 1 To 9
         With rng(n + 1, m + 4).Interior
            .ThemeColor = arrValues(n)
            .TintAndShade = 0.1 * m
         End With
      Next m
   Next n
    Range("G1:S2").Font.Bold = True
    Columns("G:I").EntireColumn.AutoFit
End Sub

如果您想知道为什么所有内置主题都显示 Light1/2 的深色和 Dark1/2 的浅色 - 这可能是一个错误,或者正如 MS 所说的那样;它是 Excel 和 Word 中的“功能”。在 Powerpoint 中,反之亦然——更符合您的预期。

于 2018-12-19T10:17:37.707 回答