简体   繁体   English

Power Point VBA-更改每个栏的颜色

[英]Power Point VBA - Change color of each bar

I need to change color of bar to red or green based on value. 我需要根据值将条形颜色更改为红色或绿色。 Code works fine on Column chart but does not work on waterfall chart. 代码在柱状图上工作正常,但在瀑布图上不工作。 It says "This action is not supported." 它说:“不支持此操作。”

Please help making below code waterfall chart compatible: 请帮助使以下代码瀑布图兼容:

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

This changes the bars in a waterfall chart to be gray (that's the RGB) You should be able to modify it to suit your needs 这会将瀑布图中的条形更改为灰色(即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

Getting xvalues from the chart, try this 从图表中获取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

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

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