Home > Software engineering >  Listing the selected slide index numbers
Listing the selected slide index numbers

Time:03-09

I have a large presentation and I'm looking to select a number of slides positioned a different positions and receive a list of the slide index numbers. My idea is for this list to appear in a message box.

So far I have put together the below which gives me each slide number in different message boxes. I'm looking for a list to appear in 1 message box that I can copy and paste into an email.

Ideally I'd like to add some extra text to the message box so I can copy and paste to a pre made email. I can probably take that part on though.

Any help would be greatly received.

Sub ShowMeSlideNumbers()

Dim oSld As Slide

For Each oSld In ActiveWindow.Selection.SlideRange

MsgBox "The slide index of the current slide is:" & oSld.SlideIndex

Next oSld

Exit Sub

End Sub

CodePudding user response:

You can do this by creating an array to store the selected index numbers. Then read the array numbers back in reverse order to create a string. Finally, display that string as part of a MsgBox:

Sub ShowMeSlideNumbers()
    Dim oSld As Slide
    Dim X As Integer, Y As Integer, arrSlideNumbers() As Integer
    Dim strSlideNumbers As String
    
    X = 0
    
    For Each oSld In ActiveWindow.Selection.SlideRange
        ReDim Preserve arrSlideNumbers(X)
        arrSlideNumbers(X) = oSld.SlideIndex
        X = X   1
    Next oSld
    For Y = UBound(arrSlideNumbers) To 2 Step -1
        strSlideNumbers = strSlideNumbers & CStr(arrSlideNumbers(Y)) & ", "
    Next Y
    strSlideNumbers = strSlideNumbers & CStr(arrSlideNumbers(1)) & " and "
    strSlideNumbers = strSlideNumbers & CStr(arrSlideNumbers(0))
    MsgBox "The slide indices of the selected slides are: " & strSlideNumbers & "."
End Sub
  • Related