PowerPoint is Microsoft's state-of-the-art presentation software application, which allows you to create slide shows, multimedia presentations, kiosk displays, custom Web pages, and much more. PowerPoint also includes the Visual Basic for Applications macro language, so you can write PowerPoint macros that automate how your slides are created and presented. In addition, you can use Automation to issue PowerPoint commands from other client applications.
Automating PowerPoint from Word is similar to automating Excel and Outlook— you create a link to the Office object library using the References command, create a PowerPoint object variable using the CreateObject function, and then use the variable to run PowerPoint commands. In the following section, you'll build a simple macro that opens and runs a PowerPoint presentation right from your Word document.
Follow these steps to build a Word macro that starts PowerPoint, opens a presentation, and runs it.
ON THE WEB
The RunPresentation macro is located in the Chap62 document on the Running Office 2000 Reader's Corner page.
Visual Basic adds the Office object library to your project.
Dim ppt As Object 'create object variable Dim reply reply = MsgBox("Run PowerPoint Facts presentation?", vbYesNo) If reply = vbYes Then MsgBox ("Press spacebar to move from slide to slide.") Set ppt = CreateObject("Powerpoint.Application") ppt.Visible = True 'open and run presentation ppt.Presentations.Open "c:\pptfacts.ppt" ppt.ActivePresentation.SlideShowSettings.Run Set ppt = Nothing 'release object variable End If
This macro creates an object variable named ppt for the PowerPoint application object and then asks whether to run a PowerPoint presentation called PowerPoint Facts. If the user clicks Yes, the macro assigns the Powerpoint.Application object to the ppt variable using the CreateObject function, displays the PowerPoint application using the Visible property, and then opens the presentation file pptfacts.ppt using the Open method. The macro then runs the presentation using the Run method, and you can move from slide to slide by pressing the Spacebar.
Follow these steps to run the new macro:
Using a message box, Office asks you whether you want to run the PowerPoint Facts presentation.
Notice that this macro didn't automatically close the PowerPoint application when it finished running the slide show. We wanted to allow users to work in PowerPoint a little if they wanted.