VBA for Opening and closing powerpoint in Excel

KayJay0618

New Member
Joined
Jul 20, 2016
Messages
40
I have 4 PowerPoint Shows that I need to open, run, close in a specific order. I'd love to be able to code in each PowerPoint to close by clicking an action button and then open the next show. But I'm having trouble finding any good suggestions on the internet. So I thought perhaps opening them and closing them using Excel might work. The 4 shows are named FirstShow, SecondShow, ThirdShow and FourthShow (I know - not very original). When I get to the last slide of FirstShow, I would need to close the FirstShow and open the SecondShow, etc. They are all located in the same directory.

Any suggestions would be tremendously appreciated. I've done some vba in Excel and I'm not sure whether it would be easier to control from an Excel file or with an action button at the end of each "show".
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The Excel example below runs each show sequentially,without interruption.
I can provide a PowerPoint-only solution later if you wish. A master presentation would be easier than action buttons at the individual files.

Code:
' Excel module
Sub Main()
Dim objPres As Object, objShow As Object, objppt, ind%, si%, a
a = Array("one", "two")         ' file names
For ind = LBound(a) To UBound(a)
    Set objppt = CreateObject("PowerPoint.Application")
    Set objPres = objppt.Presentations.Open("c:\tmp\" & a(ind) & ".pptx")
    objPres.SlideShowSettings.AdvanceMode = 0  ' Advance slides manually (via code)
    Set objShow = objPres.SlideShowSettings.Run.View
    If Err.Number <> 0 Then
        objPres.Saved = True   ' (otherwise, it will ask the console whether to save!)
        objPres.Close
        Exit Sub
    End If
    For si = 1 To objPres.Slides.Count
        objShow.GotoSlide si
        If Err.Number <> 0 Then
            objPres.Saved = True
            objPres.Close: Exit Sub
        End If
        wt                      ' a few seconds for slide display
    Next
    objPres.Saved = True
    objPres.Close
    If Err.Number <> 0 Then Exit Sub
    Set objppt = Nothing
Next
End Sub
 
Sub wt()
Const d = 1000000000    ' adjust time here
Dim i&, j&
For i = 1 To d
    j = i + 5           ' meaningless calculation
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,469
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top