Power Point VBA - 更改每个条形图的颜色

时间:2018-02-19 14:01:39

标签: vba powerpoint powerpoint-vba

我需要根据值将条形颜色更改为红色或绿色。 代码在柱形图上正常工作,但在瀑布图上不起作用。它说"不支持此操作。"

请帮助制作以下代码瀑布图兼容:

Sub UpdateBarColor()

    Dim p As Point
    Dim s As Series
    Dim c As Chart

    Set c = ActiveWindow.Selection.ShapeRange(1).Chart
    Set s = c.SeriesCollection(1)

    For Each p In s.Points
        Debug.Print p.Format.Fill.ForeColor.RGB
    Next

End Sub

1 个答案:

答案 0 :(得分:1)

这会将瀑布图中的条形变为灰色(即RGB) 您应该能够根据自己的需要进行修改

Set c = ActivePresentation.Slides(1).Shapes(1).Chart.SeriesCollection(1)

   For Each p In c.Points
        p.Format.Fill.ForeColor.RGB = RGB(169, 169, 169)
    Next

从图表中获取xvalues,试试这个

Dim arr As Variant
Dim i As Integer
With ActivePresentation.Slides(1).Shapes(1).Chart.SeriesCollection(1)
arr = .XValues
For i = LBound(arr) To UBound(arr)
Debug.Print arr(i)
Next
End With