Add and Delete/Modify a PDF object at Run time (VBA)

DanielBe

New Member
Joined
Mar 20, 2014
Messages
3
Hi,

I'm currently building a semi complex application.


On sheet1, I have a list of items with the path to a PDF file. When the user select a item, I need the PDF to open on sheet2 and print the Sheet. this is the part I've done so far...
But if the user click on a new item, I need to replace the previous pdf open on sheet2, this is where I'm stuck.


To open the PDF, I do as follow :

Sheet2.OLEObjects.Add Filename:="c:\temp\sample.pdf", Link:=False, DisplayAsIcon:=False, Left:=40, Top:=550, Width:=150, Height:=10


How can I name this file so I may delete later? EX :

Sheet2.Shapes("Object 12").Delete


for this I need to know the name of the inserted shape.


Thank for the help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,
Try with
Code:
    For Each pShape In ActiveSheet.Shapes
        If pShape.Type = msoEmbeddedOLEObject Then
            If pShape.OLEFormat.progID Like "AcroExch*" Then
                Debug.Print "this is a pdf file"
                pShape.Delete
            End If
        End If
    Next
Regards,
 
Upvote 0
Thank you for the reply.
I've did something similar without seing your reply! (Great mind think alike!)
I've loop through all active shape but change the if for :

Code:
if pShape.Type = 7 then pShape.Delete

Thank again for the reply!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top