VBA图表系列将颜色填充设置为“自动”

问题描述 投票:1回答:3

我想在我的堆栈图表中突出显示一些系列 - 这是我已经实现的。但是图表是动态的,所以当我改变选择时我需要突出显示其他系列。但是之前强调的内容仍然突显出来。

我想在所有系列中运行一个循环,并在每次更改源时将系列的填充颜色指定为“自动”。然后我可以突出显示所需的系列。

我找到了2个使用属性发送颜色的选项

.Interior.Color

  • 要么

.Format.Fill.ForeColor.SchemeColor

但在那里我使用RGB颜色模型来设置颜色。

如何返回“自动”颜色,即图表模板中的默认颜色。我应该为上面的属性分配什么价值?

谢谢!

vba charts colors series
3个回答
0
投票

我用过:.Interior.Color = xlNone


0
投票

它是自定义图表模板吗?如果是这样,您可能拥有模板的RGB值的自定义列表。

否则,您可以只使用工作簿主题的默认颜色。

此代码将六种默认工作簿主题颜色重新应用于图表。如果有超过六个系列,主题颜色重复。 Excel也改变了后续六个系列的亮度,但我没有打扰。如果你需要调整亮度,我可以回来实现它。

Sub ReapplyDefaultColors()
  Dim iSrs As Long, nSrs As Long
  Dim iThemeColor As MsoThemeColorIndex
  If ActiveChart Is Nothing Then
    MsgBox "Select a chart and try again.", vbExclamation, "No Active Chart"
  Else
    iThemeColor = msoThemeColorAccent1
    With ActiveChart
      nSrs = .SeriesCollection.Count
      For iSrs = 1 To nSrs
        .SeriesCollection(iSrs).Format.Fill.ForeColor.ObjectThemeColor = _
            iThemeColor
        iThemeColor = iThemeColor + 1 ' msoThemeColorAccent2, 3, 4, etc.
        If iThemeColor > msoThemeColorAccent6 Then
          ' recycle colors
          ' should also adjust brightness
          iThemeColor = msoThemeColorAccent1
        End If
      Next
    End With
  End If
End Sub

编辑:事实证明,我们可以使用Excel 2003中已弃用但仍然有效的语法将自动格式重新应用于图表系列:

Sub ReapplyDefaultColors()
  Dim iSrs As Long, nSrs As Long
  If ActiveChart Is Nothing Then
    MsgBox "Select a chart and try again.", vbExclamation, "No Active Chart"
  Else
    With ActiveChart
      nSrs = .SeriesCollection.Count
      For iSrs = 1 To nSrs
        .SeriesCollection(iSrs).Interior.ColorIndex = xlAutomatic
      Next
    End With
  End If
End Sub

0
投票

我正在使用EXCEL2010。要重置自动栏颜色,我使用以下语法:

istogramma.Interior.Pattern = xlAutomatic

istogramma是我系列的名称

© www.soinside.com 2019 - 2024. All rights reserved.