如何从Excel复制图表并embedded到PPT?

我试图将粘贴图表从Excel复制到PPT,将图表embedded到PPT中。 我使用下面的代码:

Sub ChartToPresentation() ' Uses Early Binding to the PowerPoint Object Model ' Set a VBE reference to Microsoft PowerPoint Object Library Dim PPApp As PowerPoint.Application Dim PPSlide As PowerPoint.Slide Dim PPPres As PowerPoint.Presentation ' Reference existing instance of PowerPoint Set PPApp = GetObject(, "Powerpoint.Application") ' Reference active presentation Set PPPres = PPApp.ActivePresentation PPApp.ActiveWindow.ViewType = ppViewSlide 'Copy "Chart 2" to from "Sheet3" to Slide # 10 ' Copy "Chart 1" on "Sheet3" as a picture ActiveWorkbook.Sheets("Sheet3").ChartObjects("Chart 2").Copy ' Paste chart to Slide # 10 With PPPres.Slides(10).Shapes.PasteSpecial(DataType:=ppPasteOLEObject, _ Link:=msoTrue) ' Align pasted chart .Align msoAlignCenters, True .Align msoAlignMiddles, True End With ' Clean up Set PPSlide = Nothing Set PPPres = Nothing Set PPApp = Nothing AppActivate ("Microsoft PowerPoint") End Sub 

当我运行这个,我得到这个错误: Run time error. Shapes (unknown member):Invalid request. The specific data type is unavailable Run time error. Shapes (unknown member):Invalid request. The specific data type is unavailable

在线: With PPPres.Slides(10).Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoTrue)

我不知道为什么我得到这个错误。 我指定的数据types是PasteSpecial的数据types之一。 我怎样才能解决这个问题,并把图表粘贴成embedded图表。

提前致谢! 🙂

你想要复制的不是图表,而是图表对象图表区域
所以试试像这样:

 ActiveWorkbook.Sheets("Sheet3").ChartObjects("Chart 2").ChartArea.Copy With PPPres.Slides(10).Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoTrue) '~~> Rest of your code here End With 

这是你的尝试? HTH。