Results 1 to 2 of 2

Thread: Copy Excel diagram to existing PPT

  1. #1

    Question Copy Excel diagram to existing PPT

    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.

    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
    Attached Files Attached Files

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Mar 2008
    Kent, England
    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"
    pptpath = ThisWorkbook.Path & "\MyPowerpoint.pptx"
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2405, Build 17628.20102

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts