Consulting

Results 1 to 6 of 6

Thread: OLE Excel Object in PowerPoint - Works only once

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    5
    Location

    OLE Excel Object in PowerPoint - Works only once

    Hi,

    I would like to automate embedding excel file in my powerpoint. And it worked for me, but only once. If i rename the file and the path in the vba then it works again (once).

    [Q1] Is there some caching or locking ongoing for excel? In case of a pdf-file the problems is not visible.

    [vba code:

    Sub embed_excel()


    Dim osld As Slide
    Set osld = ActivePresentation.Slides(1)
    osld.Shapes.AddOLEObject Left:=100, Top:=10, Width:=100, Height:=100, FileName:="c:\temp\test5.xlsx", DisplayAsIcon:=msoTrue, IconLabel:="Example-Caption"


    End Sub]

  2. #2
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    5
    Location
    Extra Error Information: Run-üme error ’-2147467259 (80004005)’: Method 'AddOLEObject' of object 'Shapes' failed

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    No reason I can see why that wouldn't work (as many times as you like) - it does here in 2016

    The usual reason for that error is the target filename doesn't exist or has moved.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    5
    Location
    Hi John,

    Thank you for the feedback. I'm running Office 365 (1902) and tried the same script on an "the insider version". Due to the fact that it works with your system, I continued to explorer the possibilities why it is not working on my systems: add-ins, special config etc.

    I noticed that Excel process stays active. If I check the details of the process it is "C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE" -Embedding. After killing this process- I'm able to run the above vba script again. So this might be a possible workaround.

    With kind regards,

    Jan

  5. #5
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    5
    Location
    Office version used: 16.0.11328.20392.

    - With the code below you can repeatedly import the excel object.
    - If you add and extra object with a different filename (important) you do not have to kill the excel process and it keeps running in the background

    ---code-----

    Sub embed_excel()


    Dim osld As Slide
    Dim sKillExcel As String


    Set osld = ActivePresentation.Slides(1)
    osld.Shapes.AddOLEObject Left:=100, Top:=10, Width:=300, Height:=400, FileName:="c:\Temp\test4.xlsx", DisplayAsIcon:=msoTrue, IconLabel:="Caption 01"
    'osld.Shapes.AddOLEObject Left:=100, Top:=10, Width:=340, Height:=440, FileName:="c:\Temp\test5.xlsx", DisplayAsIcon:=msoTrue, IconLabel:="Caption 02"

    sKillExcel = "TASKKILL /F /IM Excel.exe"
    Shell sKillExcel, vbHide


    End Sub


    ---code-----
    Last edited by jvanesch; 02-02-2020 at 09:10 AM. Reason: New troubleshooting information

  6. #6
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    5
    Location
    Hi,

    Today, I installed office on a fresh machine. No pollution from add-ins and it worked without workarounds.

    [Q1] Is it possible to start excel from vba in "safe mode" not interfering with any macro?

    With kind regards,

    Jan

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
  •