简体   繁体   English

记录的 vba 代码不会更改图表中的图例颜色

[英]recorded vba code does not change legend colour in chart

The following VBA code is what I got when I recorded a macro to change the colour of series in my legend.下面的 VBA 代码是我录制宏来更改图例中系列颜色时得到的。

When I run it, it does not change the colour?当我运行它时,它不会改变颜色? Additionally is there a way I can specify the series, rather than just, series1,series2, instead I want to specify Apples, Oranges, etc..此外,有没有一种方法可以指定系列,而不仅仅是系列 1、系列 2,而是我想指定苹果、橘子等。

My code is as follows:我的代码如下:

  ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Legend.Select
    ActiveChart.Legend.LegendEntries(1).Select
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorText1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid

Try the following...尝试以下...

With ActiveSheet.ChartObjects("Chart 1").Chart
    With .Legend.LegendEntries(1).LegendKey.Format.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorText1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid
    End With
End With

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM