Tom’s Tutorials For Excel: Running a PowerPoint Presentation From Excel
Download this Excel workbook that runs a PowerPoint presentation.
Download this accompanying PowerPoint presentation.
Here is how you can run a PowerPoint presentation from Excel, with the below macro named “PowerPointSlideshow”. This macro is also in the downloadable workbook named “RunPowerPointExample” through a link at the top of this blog entry, which runs a slideshow from your PowerPoint presentation. A PowerPoint presentation example that accompanies this Excel workbook’s macro can also be downloaded from the above link.
When the slideshow is completed, you can hit the Esc key or click anywhere on the screen to show the presentation which will still be open. I placed notes in the macro to explain what the code is doing along the way, and to indicate where you can adjust the PowerPoint presentation’s name, path location, and slide viewing time.
The accompanying downloadable presentation contains 3 slides, each shown for 5 seconds that will look like the following 3 pictures:
Slide 1 of 3
Slide 2 of 3
Slide 3 of 3
Here’s the macro, same as in the downloadable workbook:
'Declare and define String variables (modify as desired).
Dim strFilePath As String, strFileName As String, strFilePathAndName
strFilePath = "C:\YourFilePath\"
strFileName = "SlideshowTest.pptx"
strFilePathAndName = strFilePath & strFileName
'Verify that the declared PowerPoint presentation name exists
'in the declared path.
If Len(Dir(strFilePathAndName, vbDirectory)) = 0 Then
MsgBox "There is no file named ''" & strFileName & "''" & vbCrLf & _
"in the path ''" & strFilePath & "''." & vbCrLf & vbCrLf & _
"Please check your PowerPoint presentation's" & vbCrLf & _
"name, and its expected location in the path" & vbCrLf & _
strFilePath & ".", 48, "Cannot continue -- file and path not found."
'Declare and define Object variables.
Dim ppApp As Object, ppPres As Object
Set ppApp = CreateObject("PowerPoint.Application")
Set ppPres = ppApp.Presentations.Open(strFilePath & strFileName)
'Establish the slides' viewing time duration.
'This example is for 5 seconds.
.advanceontime = True
.advancetime = 5
'Run the slide show.
'Express as True that the PowerPoint presentation was saved,
'if you want to close it without being prompted to save it.
ppPres.Saved = True
'Release the Object variables from memory.
Set ppPres = Nothing
Set ppApp = Nothing