Consulting

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.


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

  2. #2
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    814
    Location
    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"
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

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
  •