PowerPoint Macro: Getting Sections List

Sometimes I want to get the sections list of a PowerPoint presentation.
So I’ve made this PowerPoint VBA macro.
This macro outputs the list of sections name to the Immediate Window.

Macro Example

Sub DebugPrintSectionsList()
 
  Dim i As Long
 
  With ActivePresentation.SectionProperties
 
    For i = 1 To .Count
      Debug.Print .Name(i)
    Next i

  End With

End Sub

Description

Variable Declaration

The 3rd line declares a long integer variable named i that is used in the For…Next looping.

Sub...
 
  Dim i As Long

Starts With

The 5th line starts the With…End With statement.
This statement tells PowerPoint that following any action apply to the ActivePresentatin.SectionProperties.

Sub...
 
  Dim i As Long

  With ActivePresentation.SectionProperties

ActivePresentation property

The Application.ActivePresentation property returns the active Presentation object.

obj-PowerPoint-Application-ActivePresentation

The ActivePresentation property is a member of the PowerPoint.Global class, so we can omit the Application property.

obj-PowerPoint-ActivePresentation

Presentation.SectionProperties property

The Presentation.SectionProperties property (ActivePresentation.SectionProperties) returns the SectionProperties object.

obj-PowerPoint-Presentation-SectionPorperties

SectionProperties is not a collection

The SectionProperties is not a collection. It is a sigle object, although the last character is “s”.
The SectionProperties object does not have the Item method or property, and the SectionProperty object is not exist.

obj-PowerPoint-SectionPorperties

Starts Looping

The 7th line starts to loop through each section.
The index variable i starts at 1, then increases in steps of 1 until it reaches the max count of the sections (SectionProperties.Count).

Sub...
 
  Dim i As Long

  With ActivePresentation.SectionProperties
 
    For i = 1 To .Count

The SectionProperties.Count property returns the number of the sections in a PowerPoint presentation.

obj-PowerPoint-SectionPorperties-Count

Debug.Print

The 8th line outputs the section name to the Immediate Window.

Sub...
 
  Dim i As Long

  With ActivePresentation.SectionProperties
 
    For i = 1 To .Count
      Debug.Print .Name(i)

The SectionProperties.Name property returns the name of the section.

obj-PowerPoint-SectionPorperties-Name

Loops Back

The 9th line loops back to get the next section.

Sub...
 
  Dim i As Long

  With ActivePresentation.SectionProperties
 
    For i = 1 To .Count
      Debug.Print .Name(i)
    Next i

After all the sections evaluated, this macro ends.

Sub DebugPrintSectionsList()
 
  Dim i As Long
 
  With ActivePresentation.SectionProperties
 
    For i = 1 To .Count
      Debug.Print .Name(i)
    Next i

  End With

End Sub

Properties

http://www.relief.jp/itnote/archives/013931.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010