Search code examples
vbasortingpowerpointsections

Sort sections alphabetically in Powerpoint using VBA


I have a big PowerPoint file with many sections and I keep adding some.

I am looking for a way to sort my sections by alphabetical order.

I am sure it's doable using VBA but my knowledge are limited and I couldn't find a similar code to adapt.

Thanks a lot for your help!


Solution

  • This is based on a classic array-sort-logic - but applied to the sections.

    No idea if this is a performance issue if you have a lot of sections.

    Sub sortSections()
    
    Dim sp As SectionProperties
    Set sp = ActivePresentation.SectionProperties
    
    Dim cntSections As Long
    cntSections = sp.Count
    
    Dim i As Long, j As Long
    For i = 1 To cntSections - 1
        For j = i + 1 To cntSections
            If UCase(sp.Name(i)) > UCase(sp.Name(j)) Then
                sp.Move j, i
            End If
        Next
    Next
    
    End Sub