View Full Version : OLE Excel Object in PowerPoint - Works only once
jvanesch
01-31-2020, 03:29 PM
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]
jvanesch
02-01-2020, 07:46 AM
Extra Error Information: Run-üme error ’-2147467259 (80004005)’: Method 'AddOLEObject' of object 'Shapes' failed
John Wilson
02-01-2020, 09:54 AM
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.
jvanesch
02-01-2020, 03:19 PM
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
jvanesch
02-02-2020, 06:31 AM
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-----
jvanesch
02-03-2020, 07:11 AM
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.