How can I get the SlideIndex of a visible slide in Powerpoint when SelectionType = ppSelectionNone

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:

enter image description here 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 .

+6
source share
2 answers

David, perhaps you could use the Activate method for the Window.Pane object as follows:

 'new code: ActivePresentation.Windows(1).Panes(2).Activate 'your code Dim w as Long 'slide index variable w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex 

However, please read a few more about the Pane.ViewType property, which may be useful. In my simple test, Panes(2) and Panes(3) , but you may have a different context for invoking your unit.

+2
source

A potential workaround is here:

http://eileenslounge.com/viewtopic.php?f=30&t=1667

 If ActiveWindow.Selection.Type = ppSelectionNone Then Select Case ActiveWindow.ViewType Case ppViewNormal ActiveWindow.ViewType = ppViewSlide ActiveWindow.ViewType = ppViewNormal Case ppViewSlideSorter ActiveWindow.ViewType = ppViewSlide ActiveWindow.ViewType = ppViewSlideSorter Case Else ' ? End Select End If ' A slide should be selected now 

I don’t particularly like it, aesthetically, but it seems to work. The only thing that is normal, if the choice between the slides, it takes the choice to the first of these two slides, when I think the second will be more intuitive. I can change my code to account for this, but it is still not perfect.

+2
source

Source: https://habr.com/ru/post/945430/


All Articles