Hi all,
I wrote a sub that gets called when I need to copy and paste a chart from Excel 2010 to Powerpoint 2010. The sub gets inputs of (SlideNum, XLSSheetName, ChartName, XPos, YPos) to determine which gets copied and which slide it gets copied to.
However, I keep getting run time error 1004 (application-defined or object-defined error) on this line. "ActiveSheet.ChartObjects(ChartName).Copy"
Any help would be most appreciated!
Thanks so much!
Sub XLStoPPT(SlideNum, XLSSheetName, ChartName, XPos, YPos)
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Reference specific slide
Set PPSlide = PPPres.Slides(SlideNum)
Sheets(XLSSheetName).Activate
' Copy chart
ActiveSheet.ChartObjects(ChartName).Copy
'Go to required slide
PPApp.ActiveWindow.View.GotoSlide Index:=SlideNum
PPPres.Application.Activate
PPSlide.Shapes.PasteSpecial(DataType:=ppPastePNG).Select
' Position and size pasted chart
PPApp.ActiveWindow.Selection.ShapeRange.Left = XPos
PPApp.ActiveWindow.Selection.ShapeRange.Top = YPos
End Sub
I wrote a sub that gets called when I need to copy and paste a chart from Excel 2010 to Powerpoint 2010. The sub gets inputs of (SlideNum, XLSSheetName, ChartName, XPos, YPos) to determine which gets copied and which slide it gets copied to.
However, I keep getting run time error 1004 (application-defined or object-defined error) on this line. "ActiveSheet.ChartObjects(ChartName).Copy"
Any help would be most appreciated!
Thanks so much!
Sub XLStoPPT(SlideNum, XLSSheetName, ChartName, XPos, YPos)
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Reference specific slide
Set PPSlide = PPPres.Slides(SlideNum)
Sheets(XLSSheetName).Activate
' Copy chart
ActiveSheet.ChartObjects(ChartName).Copy
'Go to required slide
PPApp.ActiveWindow.View.GotoSlide Index:=SlideNum
PPPres.Application.Activate
PPSlide.Shapes.PasteSpecial(DataType:=ppPastePNG).Select
' Position and size pasted chart
PPApp.ActiveWindow.Selection.ShapeRange.Left = XPos
PPApp.ActiveWindow.Selection.ShapeRange.Top = YPos
End Sub