Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have some code that requires me to know what SlideIndex to operate on (e.g., where to insert a new slide, where to insert a ChartObject, etc.). About 99% of the time, I can successfully obtain the SlideIndex by:

Dim w as Long 'slide index variable
w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex

The other 0.1% of the time, when ActivePresentation.Windows(1).SelectionType = ppSelectionNone, it will fail, because (understandably) it can't obtain the SlideIndex of the selection, because there is no selection. This might occur if the user has inadvertently "selected" the space between two slides in the Outline pane.

What I would like to do, ideally, is get the SlideIndex property of the slide which is visible in the Slides pane:

enter image description here I currently have some code that tests whether the SelectionType is ppSelectionNone, so I can trap the condition, I just have not figured a way to identify the slideIndex of the Slides Pane.

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 interim solution is to use a public variable lastUsedSlide in an attempt to keep track of the most recently selected Slide. I can incorporate this with the WindowSelectionChange event, but was hoping there would be a more straightforward solution. If I thought this method would always work, I would use it, however, it potentially introduces unforeseen errors, since the lastUsedSlide is not a reliable proxy for what_slide_i_am_currently_looking_at.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

David, maybe you could use additionally Activate method for Window.Pane object like this:

'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 some more about Pane.ViewType property which could be helpful. In my simple test both Panes(2) and Panes(3) works but you could have different context of calling your sub.

share|improve this answer
    
I'll double-check, but when I tried that this morning, Activate was still leaving me with SelectionType = ppSelectionNone, and so therefore I was not able to refer to the ActivePresentation.Windows(1).Selection.SlideRange.... –  David Zemens May 20 '13 at 18:17
    
OK, I think this might actually work. Let me test it a bit more :) –  David Zemens May 20 '13 at 18:20

Potential workaround, 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 care for it, aesthetically, but it seems to work, kind of. Only thing is normallly if selection is between to slides, this forces selection to the first of those two slides, when I think the second would be more intuitive. I can modify my code to account for this, but it's still not ideal.

share|improve this answer
1  
The second might or might not be more intuitive, but it's not how PPT works. If you put the cursor between slides in sorter view or thumbnails pane then insert a new slide, it'll insert the new slide at the position of the cursor ... after the previous slide. That's possibly the logic behind how this behaves. –  Steve Rindsberg May 22 '13 at 11:31
    
@SteveRindsberg good point. For my purposes, I think it is safe to assume that when a slide is in view, the user intends the application should act on this slide (not the preceding slide). In any case, KazJaw's answer seems to do the trick by forcing the Selection back to the slide currently in view. –  David Zemens May 22 '13 at 12:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.