Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/170795

From BetaArchive Wiki

Article ID: 170795

Article Last Modified on 11/9/2000


  • Microsoft PowerPoint 97 Standard Edition

This article was previously published under Q170795


This article provides a Visual Basic code sample that connects to the Microsoft PowerPoint Viewer 97 object model. Once connected to the object model, you can write code that manipulates the objects exposed by the Viewer.


Before you write the code to control the Viewer, add a reference to the object model for the Viewer, using these steps:

Visual Basic Editor

  1. Start the Visual Basic Editor.
  2. On the Tools menu, click References.
  3. In the Available References list, click the following item:

    Microsoft PowerPointViewer 8.0 Object Library

  4. Click OK.

Microsoft Visual Basic 5.0

  1. Open the Project in Visual Basic.
  2. On the Project menu, click References.
  3. In the Available References list, click the following item:

    Microsoft PowerPointViewer 8.0 Object Library

  4. Click OK.

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

   Sub ConnectToViewer()

   ' Used for error trapping.
   On Error Resume Next

   ' Declare a variable which is used to store an object
   ' reference to the 97 Viewer.
   Dim oViewer As PowerPointViewer.Application
   Dim bIsViewerRunning As Boolean: bIsViewerRunning = True
   ' Attempt to get a reference to the PowerPoint Viewer
   ' object model. If the Viewer is running GetObject will
   ' succeed.
   Set oViewer = GetObject(, "PowerPointViewer.Application.8")
   ' Check if an error occurred when using GetObject
   If Err.Number <> 0 Then
      ' Clear the error object.
      ' GetObject failed, so lets try to create the object.
      Set oViewer = CreateObject("PowerPointViewer.Application.8")
      ' Check if error occurred when using CreateObject.
      If Err.Number <> 0 Then
         ' Enter code to handle the situation where GetObject and
         ' CreateObject fails.
         MsgBox "Cannot find Microsoft PowerPoint Viewer 97.", _
         ' End the Macro.
      End If
      ' The Viewer was started by the macro.
      bIsViewerRunning = False
   End If
   ' Display the name of the viewer in a message box.
   MsgBox oViewer.Name
   ' Quit the viewer if started by the macro.
   If bIsViewerRunning = False Then
   End If
   End Sub

Keywords: kbmacro kbcode KB170795