PowerPoint VBA: Getting an Active Slide Number

Sometimes we need to get an active slide number when we make a PowerPoint macro.
In Excel VBA, we can use the code “ActiveSheet.Index”
But in PowerPoint VBA, an ActiveSlide property is not exist.

Macro Example

The following PowerPoint VBA macro displays the active slide number in a message box.

Sub GetSlideIndex()

  MsgBox ActiveWindow.Selection.SlideRange.SlideIndex

End Sub

Description

ActiveWindow

  ActiveWindow...

The Application.ActiveWindow property returns the DocumentWindow object that represents an active document window.

obj-PowerPoint-Application-ActiveWindow

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

obj-PowerPoint-Global-ActiveWindow

DocumentWindow.Selection

The DocumentWindow.Selection property (ActiveWindow.Selection) returns the Selection object that represents the selection in the document window.

  ActiveWindow.Selection...

obj-PowerPoint-DocumentWindow-Selection

Selection.SlideRange

The Selection.SlideRange property returns the SlideRange object that represents a range of selected slides.

  ActiveWindow.Selection.SlideRange...

obj-PowerPoint-Selection-SlideRange

SlideRange.SlideIndex

So, the SlideRange.SlideIndex property returns the index number of the slide.

  ActiveWindow.Selection.SlideRange.SlideIndex

obj-PowerPoint-SlideRange-SlideIndex

Finally, the code “ActiveWindow.Selection.SlideRange.SlideIndex” is set to the parameter of the MsgBox function.

Sub GetSlideIndex()

  MsgBox ActiveWindow.Selection.SlideRange.SlideIndex

End Sub

Properties

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

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007