SeriesCollection
属性中的Series
对象来完成。legendName
的Series
。如果符合条件,则将前景色更改为指定的RGB颜色。Private Sub FormatShapeLegend(sheet As Worksheet, legendName As String, targetColor As MsoRGBType)
Dim shp As Shape
Dim chrt As Chart
Dim s As Series
For Each shp In sheet.Shapes
If shp.HasChart Then
Set chrt = shp.Chart
'Loop the dataseries to find the legend with the desired name.
For Each s In chrt.SeriesCollection
'If the name fits, go ahead and format the series.
If LCase(s.Name) = LCase(legendName) Then
s.Format.Fill.ForeColor.RGB = targetColor
End If
Next
End If
Next
End Sub
用例:
FormatShapeLegend ActiveSheet, "ISO", RGB(0, 0, 255)