PPT图表如何用VBA控制修改数据源?
Excel中可以用如下语句动态修改图表的数据源:
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SetSourceData Source:=Range("J3:O8")
请问在PPT中的图表,用VBA怎么来动态修改数据源?
我做了一个例子,可以获取图表后台的Sheet对象,但图表的对象无法获取。
Sub CommandButton1_Click() With ActivePresentation.Slides(1) Dim i As Integer, j As Integer Dim strObjectName '获取嵌入对象的名称 For i = 1 To .Shapes.Count If .Shapes(i).Type = msoEmbeddedOLEObject Then strObjectName = .Shapes(i).Name End If Next i Dim objShapes As Object ''嵌入的对象 Dim objChart As Object ''图表对象 Dim objSheet As Object ''Sheet对象 Set objShapes = .Shapes(strObjectName).OLEFormat.Object objShapes.Worksheets("Sheet1").Cells(1, 7) = "Test" End WithEnd Sub