尝试使用 vba 在 powerpoint 中查找图表系列集合的数量

Trying to find the number of chart series collection in powerpoint using vba

我正在尝试使用 vba 宏在簇状柱形图中查找最后一个系列集合索引号。例如。如果我必须找到幻灯片的数量

Sub GettingLastSlideNumber()

  With ActivePresentation
    MsgBox .Slides(.Slides.Count).SlideNumber
  End With

End Sub

以类似的方式,我试图找到簇状柱形图的最后一个系列号。

有人可以帮我解决这个问题吗?

要获取 Excel sheet 中簇状柱形图中系列集合的数量,请使用以下代码:

Option Explicit

Sub FindLastSeries_inChart()

Dim cht                     As ChartObject
Dim Series_counter          As Integer    

' modify "Sheet 1" Name to your needed Sheet, and "Chart 1" to your chart's name
Set cht = Sheets("Sheet1").ChartObjects("Chart 1")    

Series_counter = cht.Chart.SeriesCollection.Count

MsgBox "Series count in Chart is " & Series_counter    

End Sub

尝试

Sub seriescounter()
   Dim osld As Slide
   Dim oshp As Shape
   Set osld = ActivePresentation.Slides(3)      'or whatever index
   For Each oshp In osld.Shapes
      If oshp.HasChart Then
         If oshp.Chart.ChartType = xlColumnClustered Then MsgBox oshp.Chart.SeriesCollection.Count
      End If
   Next oshp
End Sub