我目前有一个带有通过excel生成的图表的powerpoint。
我需要做的是获取图表的值(或excel,无关紧要),以便做一些动画。
问题是我似乎无法让我的代码工作。
如果有更简单的方法,我会很高兴听到它!
这是我的代码:
Sub moveRectangle()
Dim pptChart As Chart
Dim pptcd As ChartData
Dim xlWorkbook As Object
Dim PPPres As Presentation
Dim pptShape2 As Shape
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim sld As Slide
Dim shp As Shape
Dim PPApp As PowerPoint.Application
'Look for existing instance
On Error Resume Next
Set PPApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'Create new instance if no instance exists
Set PPApp = CreateObject("Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
Set pptShape = PPPres.Slides(1).Shapes("Rectangle 16")
Set pptShape2 = PPPres.Slides(1).Shapes("Chart 3")
Set pptChart = pptShape2.Chart
Set pptcd = pptChart.ChartData
MsgBox (pptShape2.Name)
Set wb = pptcd.Workbook
Set ws = wb.Worksheets(1)
pptShape.Left = pptShape.Left - 40
End Sub
问题是我收到以下错误:
Method 'Workbook' of Object 'ChartData' failed
非常感谢任何帮助!
答案 0 :(得分:0)
为了让它在没有“激活”excel的情况下工作(存在全屏模式,非常烦人),必须做的是添加
With pptChart.ChartData
...
End With
这使您无需“激活excel”即可获得相同的功能