VBA图表系列将“颜色填充”设置为“自动”。 [英] VBA Chart series set Color Fill to "Automatic"

查看:293
本文介绍了VBA图表系列将“颜色填充”设置为“自动”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我正在考虑调整所有系列的循环并将每次的填充颜色分配为自动当我改变来源。然后我可以突出显示所需的系列。



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



.Interior.Color




  • OR



.Format.Fill.ForeColor.SchemeColor



但是我使用RGB颜色模型来设置颜色。 / p>

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



谢谢!

解决方案

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



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



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

  Sub ReapplyDefaultColors()
Dim iSrs只要,nSrs只要
变暗iThemeColor如MsoThemeColorIndex
如果没有ActiveChart,则
MsgBox选择图表并重试。,vbExclamation,无活动图表
其他
iThemeColor = msoThemeColorAccent1
with ActiveChart
nSrs = .SeriesCollection.Count
For iSrs = 1到nSrs
.SeriesCollection(iSrs).Format.Fill.ForeColor.ObjectThemeColor = _
iThemeColor
iThemeColor = iThemeColor +1'msoThemeColorAccent2、3、4等。
如果iThemeColor> msoThemeColorAccent6然后
'回收颜色
'也应调整亮度
iThemeColor = msoThemeColorAccent1
如果
结尾$ n
下一个
结尾$$$$ b如果
End Sub

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

  Sub ReapplyDefaultColors()
Dim iSrs尽可能长,nSrs尽可能长
如果没有ActiveChart,则
MsgBox选择图表并重试。,vbExclamation,无活动图表
其他
使用ActiveChart
nSrs = .SeriesCollection.Count
对于iSrs = 1到nSrs
.SeriesCollection(iSrs).Interior.ColorIndex = xlAutomatic
下一个

结尾如果
结束则结束


I want to highlight some series in my stack chart - this is I have implemented. But the chart is dynamic, so when I change selection I need to highlight other series. But what was highlighted previously remains highlighted.

I am thinking to tun a cycle through all series and assign Fill Color of the series as "Automatic" each time when I change the source. Then I could highlight the needed series.

I have have found 2 options to sent the color using properties

.Interior.Color

  • OR

.Format.Fill.ForeColor.SchemeColor

But there I used RGB color model to set a color.

How can I come back to "Automatic" color, that is default color in my chart template. What value should I assign to the properties above?

Thanks!

解决方案

Is it a custom chart template? If so, you may have a custom list of RGB values for the template.

Otherwise you may simply use the default colors of the workbook theme.

This code reapplies the six default workbook theme colors to the chart. If there are more than six series, the theme colors repeat. Excel also changes the brightness for subsequent sets of six series, but I have not bothered. If you need to adjust brightness, I can come back implement it.

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

Edit: It turns out that we can use the deprecated but still working syntax from Excel 2003 to reapply the automatic formatting to a chart series:

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

这篇关于VBA图表系列将“颜色填充”设置为“自动”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆