BY CATEGORY
VBA CATEGORIES
VBA - LINKING APPLICATIONS VIDEOS
VBA - linking applications videos | Excel VBA Part 28 - Creating PowerPoint Presentations
Posted by Andrew Gould on 26 March 2014
Writing VBA code in Excel doesn't only allow you to control Excel, you also have access to all of the other Office applications. This video looks at how to create presentations in Microsoft PowerPoint by writing code in Excel. You'll learn how to reference the PowerPoint Object Library, several methods for creating a new instance of the PowerPoint application, how to create new presentations and insert slides and how to copy data from Excel into PowerPoint. You'll also learn the importance of testing for which version of PowerPoint your users are running and how to write version-independent code that will work with (almost) any version of PowerPoint.
You can increase the size of the video:

You can view the video in full screen mode as shown on the left, using the icon at the bottom right of the frame.
You can also increase the quality of the video:

You can improve the resolution of the video using another icon at the bottom right of the frame. This will slow down the connection speed, but increase the display and sound quality. This icon only becomes visible when you start playing the video.
Finally, if nothing happens when you play the video, check that you're not using IE in compatibility view.
Hi,
I followed your video but encountered an error on this line:
PPSlide.Shapes.Paste
I think the reason is I am using Excel 2010, whereas you are using Excel 2013.
Can you tell me how can I adapt it to work for Excel 2010?
Thanks
Hi duggie,
This code works for PowerPoint 2010 with the code written in Excel 2010 using a reference to the Microsoft PowerPoint 14.0 Object Library:
Sub TestPresentation()
Dim ppt As PowerPoint.Application
Dim pres As PowerPoint.Presentation
Dim sld As PowerPoint.Slide
Shell "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE", vbNormalFocus
Set ppt = GetObject(Class:="PowerPoint.Application")
Set pres = ppt.Presentations(1)
Set sld = pres.Slides(1)
sld.Shapes(1).TextFrame2.TextRange.Text = "Test Presentation"
sld.Shapes(2).TextFrame2.TextRange.Text = "Wise Owl"
Set sld = pres.Slides.Add(2, ppLayoutBlank)
Worksheets("Sheet1").Range("A1:D6").Copy
sld.Shapes.PasteSpecial ppPasteOLEObject
Set sld = pres.Slides.Add(3, ppLayoutBlank)
Charts("Chart1").ChartArea.Copy
sld.Shapes.Paste
End Sub
I hope that helps!
Andrew,
Thanks for the update. Unfortunately I encountered the following problems when running your amended code:
When I copied and pasted your code into a new VBA workbook, I ran it and got this error:
Run-time error '-2147188160 (80048240)':
Presentations (unknown member): Integer out of range. 1 is not in the valid range 1 to 0.
Powerpoint is opened with a blank slide
I pressed the Debug option and this line is highlighted:
Set pres = ppt.Presentations(1)
I changed the 1 to a 0 (I wasn't sure what to do!) and pressed F5. I immediately got this error message:
Run-time error '-2147188160 (80048240)':
Presentations (unknown member): Integer out of range. 0 is not in the valid range 1 to 1.
I pressed Debug and the same line was at fault,
Set pres = ppt.Presentations(0)
so I changed it back from 0 to 1 and pressed F5.
Then I got a different error:
Run-time error '9'
Subscript out of range
though Powerpoint now contains a slide with Test Presentation and Wise Owl
Pressing debug shows this line at fault:
Charts("Chart1").ChartArea.Copy
Can you tell me if the problem lies with my Excel / Powerpoint combination or could it be something else?
Thanks
Hi duggie,
You can change this line:
Set pres = ppt.Presentations(1)
To this:
Set pres = ppt.Presentations.Add
The following line assumes that you have a chart called Chart1:
Charts("Chart1").ChartArea.Copy
You can change "Chart1" to the name of the chart you want to copy.
I hope that helps!
Incidentally, i had to use the following line in order to make PowerPoint 2010 run on my machine as I have later versions of Office installed:
Shell "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE", vbNormalFocus
If you only have Office 2010 installed you can remove the above line and then alter the line which uses the GetObject function to the version shown below:
Set ppt = CreateObject(Class:="PowerPoint.Application")