Search code examples
vbapowerpoint

Get index of active slide


I'm trying to get the index of the active slide and store it as an integer so that I can call functions and pass in the integer.

I have code that displays the index of the integer in a MsgBox. And yet, when I try to store the index as an integer, nothing happens.

This code shows an integer of the index.

Sub SlideIDX()
MsgBox "The slide index of the current slide is:" & _
  activePresentation.SlideShowWindow.View.Slide.slideIndex
End Sub

This code makes the attempt of storing an integer.

Sub slidePassInTest()
Dim passInteger As Integer
Set passInteger = activePresentation.SlideShowWindow.View.Slide.slideIndex
MsgBox (passInteger)
End Sub

I also tried not using Set.


Solution

  • This method always works for me:

    Sub SlideIDX()
    
    Dim currentSlide As Slide
    
    Dim slideIndex as Long
    
    Set currentSlide = Application.ActiveWindow.View.Slide
    slideIndex = currentSlide.SlideIndex
    
    End Sub