1

I currently have a powerpoint with a chart that was generated through an excel.

What I need to do is get the values of the chart (or the excel, doesn't matter) in order to do some animations.

The problem is that I can't seem to get my code to work.

If there is ANY easier way to do this I will be glad to hear it!

Here's my code:

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

The problem is that I'm getting the following error:

Method 'Workbook' of Object 'ChartData' failed

Any help is greately appreciated!

4

1 回答 1

0

为了让它在不“激活”excel(存在全屏模式,很烦人)的情况下工作,必须做的是添加

With pptChart.ChartData
...
End With

这使您无需“激活 excel”即可获得相同的功能

于 2013-10-28T03:23:58.977 回答