0

In PowerPoint, in "normal" view, the window is split into two panes, with a pane showing slide thumbnails on the left, and a pane showing the current slide on the right. You can select more than one slide in the left-hand panel, which is useful if you want to copy, move or delete slides.

To tell which slide(s) are currently selected in the left-hand panel, you can use ActiveWindow.Selection.SlideRange. However, if you click between slides in the left-hand (thumbnail) panel, you end up with an insertion point, and:

  • ActiveWindow.Selection.Type is zero (ppSelectionNone).
  • ActiveWindow.Selection.SlideRange gives an error.

I have a question in two halves:

  1. How can I detect this situation? (Presumably there are other cases where the selection type is "none").
  2. How can I tell where the insertion point is, so that I can insert new slides at that point?

Either VBA or VSTO code would be fine :-)

Gary McGill
  • 26,400
  • 25
  • 118
  • 202

2 Answers2

1

Answer to the first question:

' The mouse cursor can be placed between slide thumbnails in the following views:
' - Normal View / Thumbnail Pane
' - Slide Sorter View
' - Slide Master View / Thumbnail Pane
' Returns true if the cursor is in the slide gap in these cases.
Function IsSlideGap() As Boolean
    On Error Resume Next

    With ActiveWindow

        Select Case .View.Type
            Case ppViewNormal, ppViewSlideMaster
                ' If the thumbnail pane (ViewType 11 or 12 ) is active but                                       
                ' nothing is selected, we must be in the slide gap
                If .Panes(1).Active And .Selection.Type = ppSelectionNone Then IsSlideGap = True
            Case ppViewSlideSorter
                If .Selection.Type = ppSelectionNone Then IsSlideGap = True
        End Select

    End With
End Function

Answer to second question:

' Note: used by slide/gap context menus only so assumes
' either thumbnail pane or sorter view active
Function GetSlideCursorIndex() As Long
    Dim lSlides As Long ' Track the number of slides in order
                        ' to check if the temporary slide was deleted.
    Dim oSld As Slide

    lSlides = ActivePresentation.Slides.Count

    ' Insert a temporary new slide
    CommandBars.ExecuteMso "SlideNew"

    DoEvents

    Set oSld = ActiveWindow.View.Slide

    With oSld
        GetSlideCursorIndex = .SlideIndex
        .Delete
    End With

    If ActivePresentation.Slides.Count <> lSlides Then Debug.Print "Something went wrong!"
End Function
Jamie Garroch - MVP
  • 2,839
  • 2
  • 16
  • 24
  • Thanks. The second question was "How can I tell where the insertion point is, *so that I can insert new slides at that point*?", so it's slightly ironic that you're inserting a slide to answer that question :-). If it's safe to insert a slide at that point using `SlideNew` then that's job done. – Gary McGill Jan 27 '22 at 09:45
0

I just found this: http://skp.mvps.org/pptxp020.htm

Summary: switch to ppViewSlide view and then back again, and PowerPoint will select the slide before the insertion point (or the first slide, if the IP is at the start).

I'd still be interested in a better way that avoids the screen flicker inherent in this approach (and ideally does not change the selection).

Gary McGill
  • 26,400
  • 25
  • 118
  • 202