Application-defined or object-defined error

dverga

New Member
Joined
Jul 2, 2021
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
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!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,533
Messages
6,120,076
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top