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


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.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Sort a presentation based on slide titles


You want to sort a large presentation based on the slide titles.


Copy and paste the code below into a new module in a PowerPoint presentation (it needn't be the one you intend to sort; you just need to have this code available in an open presentation, then make the presentation you want to sort active). Shout out to Adam for finding and reporting problems with this routine.

Please use this ONLY on a copy of your presentation.

Option Explicit

Sub SortMe()

    Dim x As Long
    Dim rayTitles() As Variant
    Dim lIndex As Long
    ReDim Preserve rayTitles(1 To ActivePresentation.Slides.Count) As Variant

    ' collect titles and indices in array
    ' Sort array only works with 1-dimension arrays_
    ' so we'll combine the slide title and index
    ' then sort 'em out later:
    For x = 1 To ActivePresentation.Slides.Count
        rayTitles(x) = GetTitle(ActivePresentation.Slides(x)) & "|||" _
           & CStr(ActivePresentation.Slides(x).SlideID)

    ' sort the array
    Call BubbleSortVariantArray(rayTitles())

    ' rearrange:
    For x = 1 To UBound(rayTitles)
        ' split out the index of the slide
        lIndex = CLng(Mid$(rayTitles(x), InStr(rayTitles(x), "|||") + 3))
        Debug.Print rayTitles(x)
        ActivePresentation.Slides.FindBySlideID(lIndex).MoveTo _

End Sub

Function GetTitle(oSld As Slide) As String
' return the slide title for oSld if any

    Dim oSh As Shape

    For Each oSh In oSld.Shapes
        If oSh.Type = msoPlaceholder Then
            If oSh.PlaceholderFormat.Type = ppPlaceholderTitle _
                Or oSh.PlaceholderFormat.Type = ppPlaceholderCenterTitle Then
                ' it's a title
                GetTitle = oSh.TextFrame.TextRange.Text
                Exit Function
            End If
        End If

End Function

Public Sub BubbleSortVariantArray(rayIn() As Variant)

  Dim lLow As Long
  Dim lHigh As Long
  Dim intX As Long
  Dim intY As Long
  Dim varTmp As Variant

  On Error GoTo Errorhandler

  ' Get the bounds of the array
  lLow = LBound(rayIn)
  lHigh = UBound(rayIn)

  For intX = lLow To lHigh - 1
    For intY = intX + 1 To lHigh
      If rayIn(intX) > rayIn(intY) Then
        varTmp = rayIn(intX)
        rayIn(intX) = rayIn(intY)
        rayIn(intY) = varTmp
      End If
    Next intY
  Next intX

  Exit Sub

  MsgBox "There was a problem sorting the array"
  Resume NormalExit
End Sub

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

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 - 2017 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

Sort a presentation based on slide titles
Last update 29 May, 2017