Microsoft Knowledge Base

How to Test PowerPoint OLE Automation Server Objects Using OLE

Last reviewed: July 25, 1996
Article ID: Q136388
The information in this article applies to:
  • Microsoft Visual Test for Windows 95, version 4.0
  • Microsoft PowerPoint for Windows 95, version 7.0

SUMMARY

This article demonstrates how to test PowerPoint OLE Automation server objects by using Visual Test as an OLE Automation controller. Specifically, you will create a Microsoft PowerPoint 7.0 presentation consisting of two basic slides and show the presentation by using OLE automation in Visual Test.

MORE INFORMATION

In general, the key to developing test case files that test OLE automation features of an application is to understand the application's object model. The Object Browser that ships with Microsoft Excel and OLE2VIEW that ships with the OLE Software Development Kit (SDK) are tools that allow you to view OLE objects (that is, browse the object interfaces by using the Type Library). Viewing the Type Library allows you to determine which interfaces are exposed to an OLE automation controller including the OLE objects as well as their member functions. The member functions are displayed as function prototypes to allow you to view the argument types and return values. With Visual Test OLE procedures, you can create a dispatch object, get and set properties, invoke methods, and release the object when you are through with it.

The key steps when creating a PowerPoint presentation and showing the presentation are as follows:

  1. Create a PowerPoint application object.

  2. Create a new Presentation.

  3. Add Slides to the Presentation.

  4. Create SlideObjects on the Slides.

  5. Create a SlideShow object that sets higher level parameters of the slide show.

  6. Create a SlideShowWindow object.

  7. Create a SlideShowView object for purposes of controlling the slide show and monitoring its progress.

To accomplish these steps, insert the following code into a new text window:

   Dim PP As variant
   Dim AppWindow as variant
   Dim Presentations As variant, Presentation as variant
   Dim Slides As variant, Slide as Variant
   Dim SlideObjects as variant, SlideObject as variant
   Dim SlideShow as variant, SlideShowWindow as variant
   Dim SlideShowView as variant

   ' PowerPoint constants obtained from the Object Browser
   const ppLayoutText = 2
   const ppLayoutTitleOnly = 11
   const ppTrue = -1
   const ppSlideShowDone = 4
   const ppSlideShowManualAdvance = 0
   const ppSlideShowFullScreen = 0

   ' Create a new instance of PowerPoint
   PP = OLECreateObject("PowerPoint.Application")

   ' Obtain a pointer to the AppWindow object to make PowerPoint visible
   AppWindow = OLEGetProperty(PP, "AppWindow")
   OLESetProperty(AppWindow, "Visible", True)
   Pause "Is PowerPoint Visible?"

   ' Obtain a pointer to the Presentations collection
   Presentations = OLEGetProperty(PP, "Presentations")

   ' Create a new Presentation
   Presentation = OLEDispatch(Presentations, "Add", True)

   ' Obtain a pointer to the Slides collection
   Slides = OLEGetProperty(Presentation,"Slides")

   ' Create a new Slide
   Slide = OLEDispatch(Slides, "Add", 1, ppLayoutTitleOnly)

   ' Obtain a pointer to the SlideObjects collection
   SlideObjects = OLEGetProperty(Slide, "Objects")

   ' Obtain a pointer to a particular "Title" SlideObject
   SlideObject = OLEGetProperty(SlideObjects, "Title")

   ' Set the property of the SlideObject
   OLESetProperty(SlideObject,"Text","Title Only Slide")

   ' Create a new Slide, new SlideObjects, and set SlideObject properties
   Slide = OLEDispatch(Slides, "Add", 2, ppLayoutText)
   SlideObjects = OLEGetProperty(Slide, "Objects")
   SlideObject = OLEGetProperty(SlideObjects, "Title")
   OLESetProperty(SlideObject,"Text","Title and Text Slide")
   SlideObject = OLEDispatch(SlideObjects, "Item", 2)
   OLESetProperty(SlideObject, "Text", "This is the text")
   Pause "How does the Presentation look now - you can scroll to
view both Slides"

   ' Obtain a pointer to a SlideShow object and set SlideShow properties
   SlideShow = OLEGetProperty(Presentation,"SlideShow")
   OLESetProperty(SlideShow, "StartingSlide", 1)
   OLESetProperty(SlideShow, "EndingSlide", 2)
   OLESetProperty(SlideShow, "RunContinuously", ppTrue)

   ' This SlideShow will require you to manually advance the slides
   OLESetProperty(SlideShow, "AdvanceMode", ppSlideShowManualAdvance)

   ' Initiate the SlideShow, run the SlideShow fullscreen
   SlideShowWindow = OLEDispatch(SlideShow, "Run", ppSlideShowFullScreen)

   ' Create a SlideShowView for purposes of monitoring the SlideShow
   SlideShowView = OLEGetProperty(SlideShowWindow, "View")
   ' At this point, the screen will go blank as the SlideShow begins and
   ' is shown in full screen view. The test script will go into a loop
   ' as you manually advance the slides by pressing the space bar. Press
   ' the ESC key when you are finished viewing the application. It should
   ' be noted that the slide show could also be shown in automatic mode.
   ' When you press the ESc key to terminate the SlideShow, the object will
   ' go out of scope, and a trappable error will occur prior to the While
   ' Loop condition becoming false.
   On Error GoTo errdone
      While OLEGetProperty(SlideShowView,"State") <> ppSlideShowDone
         Sleep 5
      Wend
   errdone:

   ' Quit the applicaiton and release the PowerPoint application object
   OLEDispatch(PP, "Quit")
   OLEReleaseObject(PP)
   Stop
   End

Run the program. The test script will pause once to show that PowerPoint has become visible and once to show that the two slides have been created. At that point, the slide show will begin in full screen mode. You need to advance the slides by pressing the spacebar and terminate the slide show by pressing the ESC key.

As a general rule:

  • Functions that return a value but require no arguments are accessed by using the OLE Automation procedure OLEDispatch.
  • Member functions that return a value and do require arguments are accessed using the OLE Automation procedure OLEGetProperty.
  • Member functions that don't return a value are accessed using OLEDispatch.

For example, the following prototypes obtained by viewing the PowerPoint 7.0 Type Library with the Object Browser display member functions that were accessed in the above sample code:

   Object: Application, Member function: AppWindow() As ApplicationWindow
   Object: Presentation, Member function: Add(WithWindow As Variant) As
           Presentation
   Object: Application, Member function: Quit

Therefore, applying the aforementioned rules, the following Visual Test function calls would result:

   ApplicationWindow = OLEGetProperty(Application, "AppWindow")
   Presentation = OLEDispatch(Presentations, "Add", True)
   OLEDispatch(Application, "Quit")


Additional reference words: 4.00 7.00 WIN32
KBCategory: kbusage kbole kbwebcontent
KBSubCategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 25, 1996
©1997 Microsoft Corporation. All rights reserved. Legal Notices.