Inserting PDF files into Powerpoint using VBA

OliverBrain

New Member
Joined
Mar 19, 2015
Messages
30
I am trying to insert a PDF file into a powerpoint slide and have a link between the file and powerpoint.

I have written some code that first creates a PDF of some data from Excel. The code then opens a new powerpoint presentation and adds a title slide and an additional slide. I would like to be able to insert PDF into my second powerpoint slide.

Any suggestions:

select_all_icon.jpg
page_white_copy.png

<code style="margin: 0px; padding: 0px; font-style: inherit;">Sub SavePDF()
Dim PDFRange As Excel.Range
Dim Filename As String
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide

'sets the range I want as PDF
Set PDFRange = ThisWorkbook.Worksheets("sheet1").Range("Range_Test")
Filename = "Pilot Presentation" & " " _
& Format(Now, "dd-mmm-yy")

'Exports range and saves as given filename
PDFRange.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Filename, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True


'Opens Powerpoint
Set ppApp = New PowerPoint.Application


ppApp.Visible = True

ppApp.Activate

'Adds new presentation and Title slide
Set ppPres = ppApp.Presentations.Add
Set ppSlide = ppPres.Slides.Add(1, ppLayoutTitle)

'Refers to the shapes within the title slide and input what you want
ppSlide.Shapes(1).TextFrame.TextRange = "End of Pilot Presentation"
ppSlide.Shapes(2).TextFrame.TextRange = "Client Name"

'Adds second slide
Set ppSlide = ppPres.Slides.Add(2, ppLayoutBlank)
ppSlide.Select

ppSlide.InsertFromFile("c:\Test PDF 04-Jun-15.pdf") 'attempt, not sure what I am doing here



End Sub</code>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try...

Code:
ppSlide.Shapes.AddOLEObject Left:=10, Top:=10, Width:=200, Height:=200, _
    Filename:="c:\Test PDF 04-Jun-15.pdf", displayasicon:=msoTrue, link:=msoTrue

Change the position (ie. Left, Top, etc.), accordingly. Note, the AddOLEObject method contains other parameters. Have a look at PowerPoint's help file for detailed information.

Hope this helps!
 
Upvote 0
Thanks for getting back to me, but when I run your suggested line at the end of my code I get an automation error:

Run-Time error '-2147188160 (80048240)':
Automation error

Any ideas why I am getting this error?

Thanks again
 
Upvote 0
When you type the following line in the Immediate Window (VBE > Ctrl+G), what do you get?

Code:
? Dir("c:\Test PDF 04-Jun-15.pdf")
 
Upvote 0

Forum statistics

Threads
1,196,280
Messages
6,014,438
Members
441,819
Latest member
Blackov

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