I have a slide deck that I would like to reorder, based on user-defined position defined in a column within excel. The table would look something like this:
Title | Group | Year | Slide # |
---|---|---|---|
TestA | GroupA | 2010 | 1 |
Test B | GroupB | 2011 | 2 |
Test C | GroupC | 2012 | 4 |
Test D | GroupD | 2013 | 3 |
And, for coding purposes, we can assume this is on Sheet1.
The objective is to move the 3rd title to slide 4, assuming that the current slide order is chronological based on title. The below code achieves this change but moves "Test C" back to slide 3 in the last loop occurrence (which is technically correct, but not desired). The user could reorder any/all of the slides, so I can't simply hardcode a .MoveTo for this single change.
Is there an alternative approach to reorganizing slides via vba? Or a better use of .MoveTo with this scenario?
Sub ReOrderSlides()
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Set PowerPointApp = GetObject(, "PowerPoint.Application")
Set myPresentation = PowerPointApp.ActivePresentation
Dim SlideIndex As Integer
Dim i As Integer
'Set numrows = number of classes in control sheet
NumRows = Worksheets(1).Range("A2", Range("A2").End(xlDown)).Rows.Count
'select cell A2
Range("A2").Select
'Establish "For" loop to loop "numrows" number of times
For i = 1 To NumRows
'Capture user-defined slide position
SlideIndex = Worksheets(1).Cells(i + 1, 8).Value
Debug.Print i
Debug.Print SlideIndex
'Moves slide x to position y in active presentation
myPresentation.Slides(i).MoveTo toPos:=SlideIndex
ActiveCell.Offset(1, 0).Select
Next i
End Sub