PowerPoint VBA - 循环所有幻灯片、所有形状、查找图表、将数据标签颜色设置为黑色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24929913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:28:24  来源:igfitidea点击:

PowerPoint VBA - loop all slides, all shapes, find chart, set datalabel color to Black

vbaloopschartspowerpoint

提问by Boosted_d16

I'm new to PowerPoint VBA so please bear with me.

我是 PowerPoint VBA 的新手,所以请耐心等待。

I would like to:

我想要:

  1. loop through all the slides on a given pptx,
  2. loop through all the shapes on a given slide,
  3. find chart shapes
  4. loop through the chart's series collection
  5. set the datalabel color property to dark black.
  1. 循环浏览给定 pptx 上的所有幻灯片,
  2. 遍历给定幻灯片上的所有形状,
  3. 查找图表形状
  4. 循环遍历图表的系列集合
  5. 将数据标签颜色属性设置为深黑色。

So far I have been able to complete the first 3 tasks but I need help with the last 2. Here is my code:

到目前为止,我已经能够完成前 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

回答by Boosted_d16

Solved.

解决了。

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

Though I didn't successfully loop over the series in chart but this works.

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