views:

1666

answers:

1

I have an embedded PowerPoint presentation in an Excel workbook. How can I edit this (open, copy slides, add data to slides, close) using VBA?

+6  A: 

1. Add a reference to the PowerPoint Object Model to your VBA application

From the VBA window, choose Tools | References
Look for Microsoft Powerpoint 12.0 Object Library and check it

2. Select and activate the PowerPoint presentation object

ActiveSheet.Shapes("Object 1").Select
Selection.Verb Verb:=xlOpen

Note: this code assumes that the PowerPoint object is named Object 1 (look in the top left corner to see what it's really named) and that it is on the active sheet.

3. Get a reference to the Presentation object

Dim p As PowerPoint.Presentation
Set p = Selection.Object

4. Manipulate it

All the methods and properties of a presentation object are available to you. Here's an example of adding a slide:

p.Slides.Add 1, ppLayoutBlank

5. Deselect it

The easiest way is just to select a cell.

[a1].Select

Hope that helps!

Joel Spolsky
Fantastic, thanks.