【问题标题】:PowerPoint VBA - loop all slides, all shapes, find chart, set datalabel color to BlackPowerPoint VBA - 循环所有幻灯片,所有形状,查找图表,将数据标签颜色设置为黑色
【发布时间】:2014-09-15 18:49:24
【问题描述】:

我是 PowerPoint VBA 的新手,所以请多多包涵。

我想:

  1. 循环浏览给定 pptx 上的所有幻灯片,
  2. 遍历给定幻灯片上的所有形状,
  3. 查找图表形状
  4. 循环浏览图表的系列集合
  5. 将数据标签颜色属性设置为深黑色。

到目前为止,我已经能够完成前 3 个任务,但我需要最后 2 个任务的帮助。这是我的代码:

Sub test()

  Dim slide As Object
  Dim shape As Object
  Dim shapeNames As Object
  Dim chSeries As Series

  i = 0
  For Each slide In ActivePresentation.Slides

      For Each shape In slide.Shapes

          If shape.HasChart Then

              i = i + 1
              Debug.Print "found a chart on slide", i

          End If

      Next

  Next

End Sub

【问题讨论】:

    标签: vba loops charts powerpoint


    【解决方案1】:

    解决了。

    Sub test()
    
        Dim sld As Slide
        Dim shp As Shape
        Dim sr As Series
        Dim chrt As Chart
    
            For Each sld In ActivePresentation.Slides
                For Each shp In sld.Shapes
    
                    If shp.HasChart Then
                        Debug.Print shp.Chart.ChartType
    
                        If shp.Chart.ChartType = 57 Then
    
                            shp.Chart.SeriesCollection(1).DataLabels.Font.Color = RGB(0, 0, 0)
    
                         End If
    
                    End If
    
        Next shp
        Next sld
    
    End Sub
    

    虽然我没有成功遍历图表中的系列,但这很有效。

    【讨论】:

    • 如果您想在 Excel 中执行此操作,请使用 dim 作为 Powerpoint.Slide、Powerpoint.Shape 等...
    猜你喜欢
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    相关资源
    最近更新 更多