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

PPTools

Image Export converts PowerPoint slides to high-quality images.

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

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

FixLinks prevents broken links when you distribute PowerPoint presentations

Optimizer saves disk space and bandwidth, "right-sizes" your PowerPoint presentations for email, screenshow or printing

PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

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.

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 - 2011 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.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

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 07 June, 2011
Created: