PowerPoint VBA: Getting the Last Slide Number

This PowerPoint VBA macro shows us the last slide number of an active presentation.

Macro Example

Sub GettingLastSlideNumber()

  With ActivePresentation
    MsgBox .Slides(.Slides.Count).SlideNumber
  End With

End Sub

Description

[Applications.]ActivePresentation

  With ActivePresentation...

The Application.ActivePresentation property returns an active Presentation object.

obj-PowerPoint-Application-ActivePresentation

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

obj-PowerPoint-ActivePresentation

ActivePresentation.Slides (Presentation.Slides)

  With ActivePresentation...
    MsgBox .Slides(.Slides...

The ActivePresentation.Slides (Presentation.Slides property) returns the Slides collection object that represents all the slides in the active presentation.

obj-PowerPoint-Presentation-Slides

Slides.Count

  With ActivePresentation...
    MsgBox .Slides(.Slides.Count...

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

obj-PowerPoint-Slides-Count

Slides.Item

  With ActivePresentation...
    MsgBox .Slides[.Item](.Slides.Count)...

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

obj-PowerPoint-Slides-Item

The Item method is a default member of the Slides collection object. We can see a little blue marble beside its icon in the Object Browser. So we can omit the .Item .

By setting the Slides.Count to the Slides.Item method’s parameter, we can get the Slide object that represents the last slide.

Slide.SlideNumber

  With ActivePresentation...
    MsgBox .Slides[.Item](.Slides.Count).SlideNumber

The Slide.SlideNumber property returns the slide number.

obj-PowerPoint-Slide-SlideNumber

Sub GettingLastSlideNumber()

  With ActivePresentation
    MsgBox .Slides(.Slides.Count).SlideNumber
  End With

End Sub

Properties

http://www.relief.jp/itnote/archives/powerpoint-vba-get-last-slide-number.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007