PowerPoint VBA: Selecting the Last Slide

This PowerPoint VBA macro selects the last slide.

Macro Example

Sub SelectingLastSlide()

  ActiveWindow.View.GotoSlide _
    Index:=ActivePresentation.Slides.Count

End Sub

Description

[Application.]ActiveWindow

  ActiveWindow...

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

obj-PowerPoint-Application-ActiveWindow

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

obj-PowerPoint-Global-ActiveWindow

ActiveWindow.View (DocumentWindow.View)

  ActiveWindow.View...

The ActiveWindows.View (DocumentWindow.View property) returns the View object that represents a view in the document window.

obj-PowerPoint-DocumentWindow-View

View.GotoSlide

  ActiveWindow.View.GotoSlide...

The View.GotoSlide method switches to the specified slide.

obj-PowerPoint-View-GotoSlide

[Applications.]ActivePresentation

  ActiveWindow.View.GotoSlide _
    Index:=ActivePresentation...

The Application.ActivePresentation property returns an active Presentation object.

obj-PowerPoint-Application-ActivePresentation

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

obj-PowerPoint-ActivePresentation

ActivePresentation.Slides (Presentation.Slides)

  ActiveWindow.View.GotoSlide _
    Index:=ActivePresentation.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

  ActiveWindow.View.GotoSlide _
    Index:=ActivePresentation.Slides.Count

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

obj-PowerPoint-Slides-Count

Finally, by setting the ActivePresentation.Slides.Count to the View.GotoSlide method’s parameter, the last slide is displayed.

Sub SelectingLastSlide()

  ActiveWindow.View.GotoSlide _
    Index:=ActivePresentation.Slides.Count

End Sub

Properties

http://www.relief.jp/itnote/archives/powerpoint-vba-go-to-last-slide.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007