PowerPoint Macro: Hiding Only the Odd Slides

This PowerPoint VBA macro allows us to hide only the odd slides.

Macro Example

Sub HideOnlyOddSlides()

  Dim i As Long

  With ActivePresentation.Slides

    For i = 1 To .Count
      If i Mod 2 = 1 Then
        .Item(i).SlideShowTransition.Hidden = msoTrue
      End If
    Next i

  End With

End Sub

Description

Variable Declaration

The 3rd line declares a long integer type variable named i.

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.Slides (Presentation.Slides object).

Sub...

  Dim i As Long

  With ActivePresentation.Slides

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.Slides property

The Presentation.Slides property (ActivePresentation.Slides) returns the Slides collection object.

obj-PowerPoint-Presentation-Slides

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

obj-PowerPoint-Slides

Starts Looping

The 7th line starts to loop through all the elements (=Slide) of a collection (=Slides).
The index variable i starts at 1, then increases in steps of 1 until it reaches the max count of the slides (Slides.Count).

Sub...

  Dim i As Long

  With ActivePresentation.Slides

    For i = 1 To .Count

The Slides.Count property returns the number of slides in the presentation.

obj-PowerPoint-Slides-Count

Checks counter variable

The 8th line checks to see if i is odd.

Sub...

  Dim i As Long

  With ActivePresentation.Slides

    For i = 1 To .Count
      If i Mod 2 = 1 Then

Hides the Odd Slides

The 9th line hides the odd slide.

Sub...

  Dim i As Long

  With ActivePresentation.Slides

    For i = 1 To .Count
      If i Mod 2 = 1 Then
        .Item(i).SlideShowTransition.Hidden = msoTrue

This object model hierarchy is a little deep.
I will explain about this.

Slides.Item

The Slides.Item method returns a single Slide object from a Slides collection.

        .Item(i)...

obj-PowerPoint-Slides-Item

Slide.SlideShowTransition

The Slide.SlideShowTransition property returns a SlideShowTransition object that represents the special effects for the slide transition.

        .Item(i).SlideShowTransition...

obj-PowerPoint-Slide-SlideShowTransition

SlideShowTransition.Hidden

The SlideShowTransition.Hidden property returns or sets the slide is hidden during a slide show.

        .Item(i).SlideShowTransition.Hidden...

obj-PowerPoint-SlideShowTransition-Hidden

So, the 9th line hides the slides by setting the SlideShowTransition.Hidden property to msoTrue.

        .Item(i).SlideShowTransition.Hidden = msoTrue

Loops back

The 11th line loops back to evaluate the next slide.
And the 13th line ends the With…End With statement for the ActivePresentation.Slides.

Sub HideOnlyOddSlides()

  Dim i As Long

  With ActivePresentation.Slides

    For i = 1 To .Count
      If i Mod 2 = 1 Then
        .Item(i).SlideShowTransition.Hidden = msoTrue
      End If
    Next i

  End With

End Sub

After every slide is evaluated, this macro ends.

Properties

http://www.relief.jp/itnote/archives/powerpoint-vba-hyde-odd-or-even-slides.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007