GetActiveSlide

The routine given below returns the active slide in any view. The Selection object has a type that indicates what has been selected. You can select slides, shapes or text. The Selection object has three distinct members - SlideRange, ShapeRange and TextRange - corresponding to these selections. One thing to note is that: irrespective of what the selection is, PowerPoint still keeps valid entries in SlideRange member of the Selection object. The GetActiveSlide() function makes use of this knowledge.

Function GetActiveSlide(ByVal Wnd As Object) As Slide
    Dim Sld As Slide

    Select Case TypeName(Wnd)
        Case "DocumentWindow"
            Set Sld = Wnd.Selection.SlideRange(1)
        Case "SlideShowWindow"
            Set Sld = Wnd.View.Slide
    End Select

    Set GetActiveSlide = Sld
End Function

Sub TestDesignWindow()
    MsgBox "Active Slide Index =" + _
        Str(GetActiveSlide(ActiveWindow).SlideIndex)
End Sub

Sub TestSlideShowWindow()
    If SlideShowWindows.Count > 0 Then
        MsgBox "Active Slide Index =" + _
            Str(GetActiveSlide(SlideShowWindows(1)).SlideIndex)
    End If
End Sub

Contact OfficeOne on email at officeone@officeoneonline.com. Copyright © 2001-2023 OfficeOne. All rights reserved.