OfficeTips Home || VBA Section || General Section ||  Download Section  ||  Privacy Policy

Start a slide show and monitor it from an external application using events

This example starts a PowerPoint show from a VB application and monitors the status of the show by trapping the events fired by the PowerPoint application. To set the VB application, open Visual Basic, Select a Standard exe. Place a list box and a command box on the form. Set a reference to the PowerPoint object library. Copy/paste the code given below into the code module of the form.

Download VB Project (requires Visual Basic):


' --------------------------------------------------------------------------------
' Copyright ©1999-2014 Shyam Pillai. All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------

Option Explicit
Option Explicit
Dim WithEvents oPPTAppEvents As PowerPoint.Application
Dim oPPTApp As PowerPoint.Application
Dim oPPTPres As PowerPoint.Presentation
Dim PresPath As String
Private Sub Command1_Click()
Call AutomatePowerPoint
End Sub
Sub AutomatePowerPoint()
    On Error Resume Next
    PresPath = "F:\Test\Test.ppt"
    Set oPPTApp = CreateObject("PowerPoint.Application")
    If Not oPPTApp Is Nothing Then
        Set oPPTAppEvents = New PowerPoint.Application
        List1.AddItem "All slide show events are being monitored..."
        With oPPTApp
            Set oPPTPres = .Presentations.Open(PresPath, , , False)
            If Not oPPTPres Is Nothing Then
                oPPTPres.SlideShowSettings.Run
            Else
                MsgBox "The code could not open the specified file." & _
                        "Check if the file is present at the location.", _
                        vbCritical + vbOKOnly, "PowerPoint Automation Example"
            End If
        End With
    Else
        MsgBox "The code failed to instantiate PowerPoint session.", _
                vbCritical + vbOKOnly, "PowerPoint Automation Example"
    End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
    Set oPPTPres = Nothing
    oPPTApp.Quit
    Set oPPTApp = Nothing
End Sub
Private Sub oPPTAppEvents_SlideShowBegin( _
	ByVal Wn As PowerPoint.SlideShowWindow)
List1.AddItem "Slide show has begun..."
End Sub
Private Sub oPPTAppEvents_SlideShowEnd( _
	ByVal Pres As PowerPoint.Presentation)
List1.AddItem "Slide show has terminated"
End Sub
Private Sub oPPTAppEvents_SlideShowNextBuild( _
	ByVal Wn As PowerPoint.SlideShowWindow)
List1.AddItem vbTab & "Slide show next build..."
End Sub
Private Sub oPPTAppEvents_SlideShowNextSlide( _
	ByVal Wn As PowerPoint.SlideShowWindow)
List1.AddItem "Next slide event..."
List1.AddItem vbTab & "Current slide: " & Wn.View.Slide.SlideIndex
End Sub

 

 
   
 

Copyright 1999-2014 (c) Shyam Pillai. All rights reserved.