Is there a direct way to get a slide index in a PowerPoint presentation?

I am trying to programmatically copy a slide into a PowerPoint presentation and paste it right after the original.

My first thought was to get the index of the old slide and add a copy to the desired new index, but I cannot find an easy way to get this index. I expected to have something like Slides.IndexOf(Slide slide)that, but could not find anything like it. I ended up writing old school code that seems to work, but I'm curious if there is a better way to do this.

var slide = (PowerPoint.Slide)powerpoint.ActiveWindow.View.Slide;
var slideIndex = 0;
for (int index = 1; index <= presentation.Slides.Count; index++)
{
    if (presentation.Slides[index] == slide)
    {
        slideIndex = index;
        break;
    }
}

This is C # / VSTO, but any input that can put me on the right path is appreciated, be it VBA or VB!

+5
source share
1 answer

, Duplicate, SlideRange. VBA:

Sub DuplicateSlide()
    Dim ap As Presentation
    Set ap = ActivePresentation
    Dim sl As SlideRange
    Set sl = ap.Slides(2).Duplicate
End Sub

, :

Sub GetSlideIndex()
    Dim ap As Presentation
    Set ap = ActivePresentation
    Set sl = ap.Slides(2)
    Debug.Print sl.SlideIndex
End Sub
+3

All Articles