OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

How to determine the cursor position when in slide sorter view

Have you ever needed to insert slides into another presentation based on the current cursor position on that presentation in the slide sorter view? Most probably, the answer would be 'Yes' and the solution is straightforward, isn't it? Retrieve the current slide(s) selection in the target presentation and based on the slide index you can arrive at the insertion point. This works nicely except when the cursor in the target presentation has been placed between two slides or no selection has been made in the slide sorter view. The snippet below illustrates a simple workaround to handle such a situation. 


Sub GetCurrentCursorPosForSlide()
If ActiveWindow.ViewType = ppViewSlideSorter Then
    'Current cursor position is not retreived when selection is between slides.
    If ActiveWindow.Selection.Type = ppSelectionNone Then
        'Switch to slide view and back.
        ActiveWindow.ViewType = ppViewSlide
        ActiveWindow.ViewType = ppViewSlideSorter
        ' This forces a selection based on the cursor position
        ' If cursor is between 2nd and 3rd slide it will select 2nd slide
        ' If cursor is before the 1st slide it will select the 1st slide
        ' If cursor is after the last slide it will select the last slide.
        ' If still nothing is selected then there are no slides in the presentation.

        If ActiveWindow.Selection.Type = ppSelectionSlides Then
            Debug.Print ActiveWindow.Selection.SlideRange.SlideIndex
            Debug.Print "No slides in the presentation."
        End If
        ' Get the slide reference and obtain the position. This is left as exercise.
    End If
End If
End Sub




Copyright 1999-2011 (c) Shyam Pillai. All rights reserved.