Dim oPPTApp As Object
Dim oPPTPres As Object
Dim PresPath As String
On Error Resume Next
'Set path to powerpoint here
PresPath = "C:\Training\Training Shows\" & Pname & ".pps"
Set oPPTApp = CreateObject("PowerPoint.Application")
If Not oPPTApp Is Nothing Then
With oPPTApp
Set oPPTPres = .Presentations.Open(PresPath, , , False)
If Not oPPTPres Is Nothing Then
oPPTPres.SlideShowSettings.Run
Do While .SlideShowWindows.Count > 0
DoEvents
Loop
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
Set oPPTPres = Nothing
DoEvents
oPPTApp.Quit
DoEvents
Set oPPTApp = Nothing
'MsgBox "The PowerPoint session was terminated.", _
vbInformation + vbOKOnly, "PowerPoint Automation Example"