我有一个带有图表的powerpoint演示文稿,其中包含来自excel表的数据。
我想通过powerpoint VBA编辑器编辑这些数据。
我该怎么做?我无法找到一种方法来访问excel表的数据。
招呼
答案 0 :(得分:3)
此代码允许您访问嵌入到PowerPoint演示文稿中的Excel工作表。
Sub a()
Dim oSl As PowerPoint.Slide
Dim oSh As PowerPoint.Shape
Set oSl = ActivePresentation.Slides(1)
Set oSh = oSl.Shapes(1)
With oSh.OLEFormat.Object.Sheets(1)
.Range("A1").Value = .Range("A1").Value + 1
.Range("A2").Value = .Range("A2").Value - 1
End With
Set oSl = Nothing
Set oSh = Nothing
End Sub
如果图表链接到您修改的数据,可能会自动更新。如果没有,强制重新计算。
HTH!
修改
通过以下更改,它可以在Office 2007中使用:
With oSh.OLEFormat.Object.WorkSheets(1)
.Range("A1").Value = .Range("A1").Value + 1
.Range("A2").Value = .Range("A2").Value - 1
End With