Lesson 33Working with PowerPoint from Excel
With each new release of its Office suite, Microsoft has made it increasingly easier to share information between applications. Copying data from Excel, such as a worksheet range or chart, and pasting it into a PowerPoint slide is as simple as copying and pasting from Excel into a Word document.
Still, PowerPoint is a unique animal in that its primary purpose is not to manipulate data but to display images of data for presentation purposes. When you need to transfer data from Excel to PowerPoint, such as a chart or a range of cells, I recommend you use VBA's CopyPicture
method, which pastes an image of the data—not the data itself—into PowerPoint.
Creating a New PowerPoint Presentation
Creating a new PowerPoint presentation file is an uncomplicated process; all you do is follow the usual steps for creating the PowerPoint application and then add a presentation with the expression Presentations.Add
. Here's an example from start to finish, ending up with a new presentation file and an initial slide:
Sub CreateNewPresentation() 'Declare Object variables for the PowerPoint application 'and for the PowerPoint presentation file. Dim ppApp As Object, ppPres As Object 'Declare Object variable for a PowerPoint slide. Dim ppSlide As Object 'Open PowerPoint. Set ppApp = CreateObject("PowerPoint.Application") 'Make the PowerPoint application visible. ppApp.Visible = msoTrue 'Create a new Presentation and add a slide. Set ppPres = ppApp.Presentations.Add ...
Get Excel VBA 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.