Microsoft KB Archive/170795

= PPT97: VB Code to Connect to the Viewer 97 Object Model =

Article ID: 170795

Article Last Modified on 11/9/2000

-

APPLIES TO


 * Microsoft PowerPoint 97 Standard Edition

-



This article was previously published under Q170795



SUMMARY
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.



MORE INFORMATION
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
 Start the Visual Basic Editor. On the Tools menu, click References. In the Available References list, click the following item:

Microsoft PowerPointViewer 8.0 Object Library

 Click OK.

Microsoft Visual Basic 5.0
 Open the Project in Visual Basic. On the Project menu, click References.</li> In the Available References list, click the following item:

Microsoft PowerPointViewer 8.0 Object Library

</li> Click OK.</li></ol>

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 Err.Clear

' 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. Err.Clear ' 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.", _ vbCritical ' End the Macro. End 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 oViewer.Quit End If  End Sub

Keywords: kbmacro kbcode KB170795

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.