I have code that requires me to know what SlideIndex work for (for example, where to insert a new slide, where to insert ChartObject, etc.). In approximately 99% of cases, I can successfully get SlideIndex by:
Dim w as Long 'slide index variable w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex
Another 0.1% of the time when ActivePresentation.Windows(1).SelectionType = ppSelectionNone , it will fail because (understandably) it cannot get SlideIndex choice because there is no choice. This can happen if the user accidentally "selects" the space between two slides in the "Contour" panel.
What I would like to do, ideally, get the SlideIndex property of the slide, which is visible in the Slides panel:
Currently, I have code that checks if SelectionType ppSelectionNone , so I can catch the condition, I just did not understand the way to determine the slide index of the slide area.
Function GetMySlide() Dim w as Long If Not ActivePresentation.Windows(1).Selection.Type = ppSelectionNone Then w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex Set GetMySlide = ActivePresentation.Slides(w) Else: MsgBox "No slide is currently selected. Please select a slide in the Outline pane in order to proceed.", vbInformation Set GetMySlide = Nothing Exit Function End If End Function
Update
My intermediate solution is to use the public variable lastUsedSlide to track the last slide selected. I can enable this WindowSelectionChange event, but was hoping there would be a simpler solution. If I thought this method would always work, I would use it, however it potentially introduces unexpected errors, since lastUsedSlide not a reliable proxy for what_slide_i_am_currently_looking_at .
source share