PDA

View Full Version : Powerpoint macro to attach an object



lahuva
07-08-2011, 11:35 AM
Hello. I am new to this forum, new to Powerpoint, and especially new to Powerpoint macros and now sadly Record macro is gone.

Basically I need to attach a pdf to a page (step one), resize it (step two), and then open a new page (step three) and do the same again until I attach my five pdfs to five pages. I need to attach the same reports updated monthly. Rather than manually attach the reports I would like to do this automatically.

I believe I can do step two (thanks to a short and sweet web land tutorial - ActiveWindow.Selection.ShapeRange.Width = 500) and step three (thanks to VBA Express site: Set Sld = Pre.Slides.Add(Index:=Pre.Slides.Count + 1, Layout:=ppLayoutText) but not step one.

In Excel the code for step one would be

ActiveSheet.OLEObjects.Add Filename:="Q:\GPMS\LFA\Queries\AC Query Results\Top 50 Clients Pie.pdf", Link:=False, DisplayAsIcon:=False

However just replacing ActiveSheet with ActivePresentation does not seem to work in Powerpoint as there is not an OLEObjects choice.

Does anyone have the powerpoint vba code to do this or have any other suggestions?

Thanks

Leah

John Wilson
07-09-2011, 01:52 AM
This should give you a start:

You can add the size and position when you add the object

Sub add_pdf()
Dim osld As Slide
Set osld = ActivePresentation.Slides(1)
osld.Shapes.AddOLEObject Left:=100, Top:=10, Width:=300, Height:=400, FileName:="C:\Users\John\Desktop\test.pdf"
End Sub