I'm very new to VBA.
I'm trying to copy some charts into a pptx template, using this basic code:
Option Explicit
Sub CreatePowerPointTemplateM4()
Dim PowerPointApp As PowerPoint.Application
Dim PowerPointPrsn As PowerPoint.Presentation
Dim Chrt As ChartObject
Dim strpath As String
strpath = ThisWorkbook.Path & "\My_Template.pptx"
Set PowerPointApp = New PowerPoint.Application
Set PowerPointPrsn = PowerPointApp.Presentations.Open(strpath)
' get chart #5 and copy it into slide #7
Set Chrt = Worksheets("Graphs").ChartObjects(5)
Chrt.Copy
DoEvents
PowerPointPrsn.Slides(7).Shapes.PasteSpecial DataType:=ppPasteMetafilePicture
End Sub
This code has worked on my laptop for a few days. Now I get Run-time error '1004': Application-defined or object-defined error.
How is it possible??
The Chrt variable is defined as Chart.Object and it does contain the Copy method.
Many thanks to whom can solve this!
I'm trying to copy some charts into a pptx template, using this basic code:
Option Explicit
Sub CreatePowerPointTemplateM4()
Dim PowerPointApp As PowerPoint.Application
Dim PowerPointPrsn As PowerPoint.Presentation
Dim Chrt As ChartObject
Dim strpath As String
strpath = ThisWorkbook.Path & "\My_Template.pptx"
Set PowerPointApp = New PowerPoint.Application
Set PowerPointPrsn = PowerPointApp.Presentations.Open(strpath)
' get chart #5 and copy it into slide #7
Set Chrt = Worksheets("Graphs").ChartObjects(5)
Chrt.Copy
DoEvents
PowerPointPrsn.Slides(7).Shapes.PasteSpecial DataType:=ppPasteMetafilePicture
End Sub
This code has worked on my laptop for a few days. Now I get Run-time error '1004': Application-defined or object-defined error.
How is it possible??
The Chrt variable is defined as Chart.Object and it does contain the Copy method.
Many thanks to whom can solve this!