Create a custom show from current slide selection using VBA
Problem
You need to create a custom show programmatically using VBA, for example, from a selection of slides the user's made in the slide sorter.
Solution
The following code creates a custom show from the current selected slides. You can adapt it to other purposes by changing the portion that creates and fills the array of SlideIDs (MySlideIDs).
Sub CreateCustomShowFromSelection()
Dim x As Long
Dim MySlideIDs() As Long
With ActiveWindow.Selection.SlideRange
' add the SlideID of each slide in current
' selection to an array
' start with one member in the array
ReDim MySlideIDs(1 To 1) As Long
' step BACKWARDS through selection, else
' the show will be in reverse order:
For x = .Count To 1 Step -1
MySlideIDs(UBound(MySlideIDs)) = .Item(x).SlideID
ReDim Preserve MySlideIDs(1 To UBound(MySlideIDs) + 1)
Next
End With
' now create a custom show using the array
With ActivePresentation.SlideShowSettings.NamedSlideShows
' delete the custom show if it already exists:
On Error Resume Next
.Item("My New Show Name").Delete
On Error GoTo 0
Call .Add("My New Show Name", MySlideIDs)
End With
End Sub
See How do I use VBA code in PowerPoint? to learn how to use this example code.