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

标签 vba loops charts powerpoint

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

我想要:

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

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

    最佳答案

    解决了。

    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
    

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

    关于vba - PowerPoint VBA - 循环所有幻灯片、所有形状、查找图表、将数据标签颜色设置为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24929913/

    相关文章:

    Excel vba从不同的Excel应用程序访问工作簿实例

    mysql - Excel VBA : recordset joining and performance

    javascript - 数组值替换为对应的id

    javascript - 流程图 : How to remove/hide tick values along y-axis?

    javascript - 倾斜的 Highcharts 轴标签与图例重叠

    vba - 将许多工作表的相同范围的单元格从一本书复制/粘贴到另一本书

    arrays - 数组在代码结束后保留​​值

    c - 获取字符串的索引

    linux - 创建 bash 脚本以自动执行分析多个文件的任务

    javascript - Recharts - 归一化堆叠条形图