简体   繁体   中英

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.

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..

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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