0

I am working on a Powerpoint addin, that helps with creating agenda slides. I have to insert a slide at a specific location, which is easy using presentation.Slides.AddSlide(index, customlayout). But since I am also using sections, this always inserts the slide inside the first (default) section.

Here's an example structure. I would like to replace Page 1 at it 's current position. For this I would need to insert a slide at slideIndex=2, but as it stands now, the slide will end up below "Header Page".

  • Default Section
    • Header Page
  • Section 1
    • Page 1
    • Page 2

And here is some code I am using

private static PPT.Slide RefreshDefaultAgendaFormat(PPT.Presentation presentation, PPT.CustomLayout customAgendaLayout, PPT.Slide currentSlide)
    {
        int tempindex = currentSlide.SlideIndex;
        int tempSectionIndex = currentSlide.sectionIndex;

        currentSlide.Delete();
        currentSlide = presentation.Slides.AddSlide(tempindex, customAgendaLayout);

        return currentSlide;
    }
Niels Ziegler
  • 466
  • 2
  • 6
  • 15

1 Answers1

0

I managed to solve it by changing the order of operations and adding it at the current index+1.

    int tempindex = currentSlide.SlideIndex;
    int tempSectionIndex = currentSlide.sectionIndex;
    PPT.Slide newSlide = presentation.Slides.AddSlide(tempindex + 1, customAgendaLayout);
    currentSlide.Delete();
    return newSlide;
Niels Ziegler
  • 466
  • 2
  • 6
  • 15