I was recently trying to help someone on a forum with a very simple question: “How can I open a PowerPoint presentation using VBA, a macro”?
Simple. Copy the following function into a standard module
'---------------------------------------------------------------------------------------
' Procedure : OpenPPT
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Open a PowerPoint presentation
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sFile : Fully qualified path and file name of the PowerPoint presentation
' to open.
' bRunAsSlideShow : True/False whether to start the presentation in (True) slideshow
' mode or (False or omitted) not (standard mode).
'
' Usage:
' ~~~~~~
' Call OpenPPT("C:\Users\Daniel\Documents\MyTest.ppt")
' Call OpenPPT("C:\Users\Daniel\Documents\MyTest.ppt", True)
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2013-Nov-08 Initial Release
' 2 2014-Mar-26 Added Slideshow parameter
'---------------------------------------------------------------------------------------
Function OpenPPT(sFile As String, Optional bRunAsSlideShow As Boolean)
Dim oPPT As Object
On Error Resume Next
Set oPPT = GetObject(, "PowerPoint.Application") 'See if PowerPoint is already running
If Err.Number <> 0 Then 'Nope, so open a new instance to work with
Err.Clear
Set oPPT = CreateObject("PowerPoint.Application")
End If
On Error GoTo Error_Handler
oPPT.Visible = True
oPPT.Presentations.Open (sFile)
If bRunAsSlideShow Then oPPT.ActivePresentation.SlideShowSettings.Run
Error_Handler_Exit:
On Error Resume Next
Set oPPT = Nothing
Exit Function
Error_Handler:
MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: OpenPPT" & vbCrLf & _
"Error Description: " & Err.Description, _
vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Function
As indicated in the procedure header, then you need only call the function whenever you wish to open a presentation using 1 single line:
Call OpenPPT("C:\Users\Daniel\Documents\MyTest.ppt")
Obviously, replace “C:\Users\Daniel\Documents\MyTest.ppt” with your path and filename and do not forget the file extension.
Hope this helps.
shouldn’t the comment on function line 4 be “See if Powerpoint is already running” rather than “See if Outlook is already running”?
Yes, indeed. I’ve corrected the inline comment. Thank you for pointing that out.