Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

powerpoint

vba

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.

like image 363
David Zemens Avatar asked May 20 '13 14:05

David Zemens


People also ask

How do I select an image behind text in Powerpoint?

To select objects that are hidden, stacked, or behind text, click Select Objects, and then click and drag over the objects. To open the Selection pane, where you can select, multi-select, show, hide, or change the order of objects, click Selection Pane, and then click the options that you want.

How do I select multiple images in Powerpoint?

Click. The easiest way to select multiple objects on a slide is to hold down the Shift key and start clicking. For instance, to select the title and image in the slide shown below, click either, hold down Shift, and click the other.


1 Answers

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.

like image 142
David Zemens Avatar answered Oct 04 '22 04:10

David Zemens