Log in

View Full Version : Copy Excel diagram to existing PPT



o0omax
07-15-2022, 12:06 AM
Hello everyone


I want to copy an Excel diagram "MyDiagram" from the Excel file "MyExcel" with VBA into the PPT file "MyPowerPoint". However, if a diagram with the same name already exists, it should only be replaced so that there are not 2 same diagrams in the Powerpoint.


Problem:
Unfortunately, when I try to open "MyPowerpoint" (same file path as "MyExcel"), I get the following error.


Run-time error '-2147467259 (80004005)': Method 'Open' of object 'Presentations' failed

PS: my whole computer is synchronized with OneDrive, which is why I have already received the error message that the file name must not contain more than 255 characters. Workaround?

Here is my code in Module 1 to open existing powerpoint:

Option Explicit
Sub UpdateChartPPT()
Dim pptpath As String
Dim PP As Object
Dim PPpres As Object


pptpath = CurDir & "MyPowerpoint.pptx"


MsgBox pptpath


Set PP = CreateObject("PowerPoint.Application")
Set PPpres = PP.Presentations.Open(pptpath)
PP.Visible = msoCTrue


End Sub

georgiboy
07-19-2022, 06:14 AM
CurDir is not providing the location of the spreadsheet running the code.

If you want to open the PP presentation from the same location as the Excel file then change this line:

pptpath = CurDir & "MyPowerpoint.pptx"
To

pptpath = ThisWorkbook.Path & "\MyPowerpoint.pptx"