Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

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

This code creates a custom show from the current selected slides.

To use it, put PowerPoint in Slide Sorter view. Click the first slide you want to add to your custom show, Ctrl+Click the other slides you want to include, then run the code below to create a custom show from the selected slides.

Why the emphasis on Ctrl+Clicking? Because PowerPoint is sometimes weird and inconsistent.

If you select a range of slides by clicking the first slide then Shift+Clicking the last slide, the order of the slides in the resulting custom show will be unpredictable, probably reversed, with some slides completely out of order.

Option Explicit

Sub CreateCustomShowFromSelection()

    Dim x As Long
    Dim MySlideIDs() As Long
    Dim sShowName As String

    ' Did the user select some slides?  If not, quit:
    If ActiveWindow.Selection.Type <> ppSelectionSlides Then
        MsgBox "Please select one or more slides in the" _
                      & " SLIDE SORTER, then try again"
        Exit Sub
    End If

    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
            Debug.Print .Item(x).Name
            ReDim Preserve MySlideIDs(1 To UBound(MySlideIDs) + 1)
        Next

    End With

    ' Get a name for the show
    sShowName = InputBox("Name for your custom show:", _
                            "Custom show name", "")

    ' Quit if blank
    If Len(sShowName) = 0 Then
        Exit Sub
    End If

    ' 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(sShowName).Delete
        On Error GoTo 0

        Call .Add(sShowName, MySlideIDs)

    End With

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Background


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Create a custom show from current slide selection using VBA
http://www.pptfaq.com/FAQ00869_Create_a_custom_show_from_current_slide_selection_using_VBA.htm
Last update 04 May, 2016
Created: