Using PowerPoint Objects

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.

Creating the RunPresentation Macro

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.

  1. In Word, choose Macros from the Macro submenu of the Tools menu.
  2. Type RunPresentation, and then click Create.
  3. From the Visual Basic Tools menu, choose References.
  4. Verify that the Microsoft Office 9.0 Object Library is selected.
  5. Click OK to close the References dialog box.

    Visual Basic adds the Office object library to your project.

  6. Type the following code in the RunPresentation macro using the Code window:
  7.  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

  8. Edit line eight of your macro to change the PowerPoint presentation pathname to a real location on your hard disk. If you would like to download a presentation ready-made, you'll find several on the Running Office 2000 Reader's Corner page.
  9. Click the Save button to save the macro to disk.

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.

Running the RunPresentation Macro

Follow these steps to run the new macro:

  1. Click the View Microsoft Word button on the Visual Basic Editor toolbar.
  2. Press Alt+F8 to open the Macros dialog box, and then double-click the RunPresentation macro.

    Using a message box, Office asks you whether you want to run the PowerPoint Facts presentation.

  3. Click Yes, and then click OK when you are instructed to press the Spacebar during the slide show. Word starts the PowerPoint presentation and loads the first slide.
  4. Examine each slide in the presentation, pressing the Spacebar to move from one to the next.
  5. When you have finished reviewing the slide show, click the Close button on the PowerPoint title bar to quit the application and return to your document.

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.



Running Microsoft Office 2000 Small Business
Running Microsoft Office 2000
ISBN: 1572319585
EAN: 2147483647
Year: 2005
Pages: 228

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net