I am trying to code an automatic agenda/table of contents generator in VBA for PowerPoint, which generates agenda bullet points based on the titles of the sections inside the PowerPoint presentation. Since I also want the agenda to appear at the beginning of every section, I am struggling with the fact that the method
.AddSlide(Index (I am inserting the ID of a section´s first slide here), pCustomLayout )
adds the slide(s) just before the section (so actually at the end of the previous section) because it's just based on an ID and does not say "insert the slide at a section's beginning".
Is there an easy solution (without deleting and recreating the section for instance) to achieve that the slides are created just at the beginning of a section and not at the end of the previous section?
Solution
Sub moveSlidesToSectionStart(pSectionIndex, pFirst, pLast)
Dim objPresentation As Presentation
Set objPresentation = Application.ActivePresentation
totalSlides = pLast - pFirst + 1
Dim arr()
ReDim arr(totalSlides - 1)
For i = 0 To totalSlides - 1 'fill array with all slides (slide numbers) that need to be moved
arr(i) = pFirst + i
Next i
objPresentation.Slides.Range(arr).MoveToSectionStart(pSectionIndex)
End Sub