PowerPoint Macro: Getting the Slides List Not Having a Title Placeholder

Sometimes, I have to get the list of slides not having a title placeholder.
So, I’ve made a PowerPoint VBA macro. This macro outputs the index of the slides to the Immediate Window.

Macro Example

Sub GetSlidesListNotHavingTitle()

  Dim sld As Slide

  For Each sld In ActivePresentation.Slides
    If Not sld.Shapes.HasTitle Then
      Debug.Print sld.SlideIndex
    End If
  Next sld

End Sub

Description

Variable Declaration

The 3rd line declares an object variable named sld that refers to a Slide object.

Sub...

  Dim sld As Slide

The Slide object represent an individual slide in a PowerPoint presentation.

obj-PowerPoint-Slide

Starts Looping

The 5th line starts to loop through all the elements (=Slide) of a collection (=Slides).

Sub...

  Dim sld As Slide

  For Each sld In ActivePresentation.Slides

ActivePresentation property

  For Each sld In ActivePresentation...

The Application.ActivePresentation property returns an active Presentation object.

obj-PowerPoint-Application-ActivePresentation

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

obj-PowerPoint-ActivePresentation

Presentation.Slides property

  For Each sld In ActivePresentation.Slides

The Presentation.Slides property (ActivePresentation.Slides) returns a Slides object.

obj-PowerPoint-Presentation-Slides

The Slides object is a collection of all the Slide object in a presentation.

obj-PowerPoint-Slides

Checks If the Slide Has a Title

The 6th line checks if the slide has a title placeholder.

Sub...

  Dim sld As Slide

  For Each sld In ActivePresentation.Slides
    If Not sld.Shapes.HasTitle Then

Slide.Shapes property

    If Not sld.Shapes...

The Slide.Shapes property (sld.Shapes) returns a Shapes collection object that represents all the shapes those have been placed on a slide.

obj-PowerPoint-Slide-Shapes

Shapes.HasTitle property

    If Not sld.Shapes.HasTitle...

The Shapes.HasTitle property returns whether the Shapes collection contains a title placeholder.

obj-PowerPoint-Shapes-HasTitle

Outputs the Slide Index

If the slide does not have the title, the 7th line outputs the slide index to the Immediate Window.

Sub...

  Dim sld As Slide

  For Each sld In ActivePresentation.Slides
    If Not sld.Shapes.HasTitle Then
      Debug.Print sld.SlideIndex

The Slide.SlideIndex property returns the index number of the slide.

obj-PowerPoint-Slide-SlideIndex

Loops Back to Get the Next Slide

The 9th line loops back to get the next Slide object.

Sub...

  Dim sld As Slide

  For Each sld In ActivePresentation.Slides
    If Not sld.Shapes.HasTitle Then
      Debug.Print sld.SlideIndex
    End If
  Next sld

After every slide is evaluated, this macro ends.

Sub GetSlidesListNotHavingTitle()

  Dim sld As Slide

  For Each sld In ActivePresentation.Slides
    If Not sld.Shapes.HasTitle Then
      Debug.Print sld.SlideIndex
    End If
  Next sld

End Sub

Properties

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

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007