Detecting I-beam cursor position in slidesorter

  • Thread starter Thread starter Martin Stender
  • Start date Start date
M

Martin Stender

Hi all,

I have a bit of trouble inserting slides in the correct place, when the
slidesorter is in focus and the user has not actually selected a slide.
(f.x. if the curser is inserted between two slides).

Paste the following into a commandbutton (and add a few slides):

Private Sub CommandButton1_Click()


If ActiveWindow.Presentation.Slides.Count = 0 Then
currSlide = 0
debugMsg = "empty presentation"
ElseIf ActiveWindow.Selection.Type = ppSelectionSlides Then
currSlide = ActiveWindow.Selection.SlideRange.SlideIndex
debugMsg = "selected slide in slidesorter"
ElseIf ActiveWindow.Selection.Type = ppSelectionNone Or _
ppSelectionShapes Or ppSelectionText Then

'this is where the code fails
currSlide = ActiveWindow.View.Slide.SlideIndex
debugMsg = "none, shapes or text"
Else
currSlide = ActivePresentation.Slides.Count 'last slide
debugMsg = "last slide"
End If

Debug.Print currSlide, debugMsg

'in real life the following would be insertFromFile'
ActivePresentation.Slides.Add Index:=currSlide + 1, _
Layout:=ppLayoutBlank

ActiveWindow.View.GotoSlide currSlide + 1


End Sub

I can of course insert an "On Error Resume Next", but then the user
will just be mystified, when nothing happens.

Any suggestions?

Thanks in advance
Martin
 
It's a known problem, Martin. I don't know of any answer other than to trap
the error. Perhaps instruct the user to click on the slide they want to insert
after and try again.
 
Thanks again, Steve for saving me hours trying get the cursor position
from the thumbnail view.

I did find another way, however. Even though it's a bit messy, it could
be useful for somebody, so I might as well post it:

Private Sub CommandButton1_Click()

'<new stuff>
Select Case ActiveWindow.ActivePane.ViewType
Case 1, 7, 11 'the views we can insert slides in
'do nothing - continue
Case Else 'else notify the user to change view
MsgBox "Please switch to Normal View or" & vbCrLf & _
"Slide Sorter View to insert slides.", vbExclamation
Exit Sub 'get out
End Select

If ActiveWindow.ActivePane.ViewType = ppViewThumbnails Or _
ppViewSlideSorter Then 'we are in Thumbnail or slidesorter view"

If ActiveWindow.Selection.Type = ppSelectionNone Then
'nothing selected

'in case we need to return to slidesorter view
previousViewType = ActiveWindow.ViewType

'switch to normal view if needed
ActiveWindow.ViewType = ppViewNormal

'activate slide pane
ActiveWindow.Panes(2).Activate

'return to slidesorter view, if we came from that
ActiveWindow.ViewType = previousViewType

End If

End If
'</new stuff>


If ActiveWindow.Presentation.Slides.Count = 0 Then
currSlide = 0
debugMsg = "empty presentation"
ElseIf ActiveWindow.Selection.Type = ppSelectionSlides Then
currSlide = ActiveWindow.Selection.SlideRange.SlideIndex
debugMsg = "selected slide in slidesorter"
ElseIf ActiveWindow.Selection.Type = ppSelectionNone Or _
ppSelectionShapes Or ppSelectionText Then
currSlide = ActiveWindow.View.Slide.SlideIndex
debugMsg = "none, shapes or text"
Else
currSlide = ActivePresentation.Slides.Count 'last slide
debugMsg = "last slide"
End If

Debug.Print currSlide, debugMsg

'in real life the following would be insertFromFile'
ActivePresentation.Slides.Add Index:=currSlide + 1, _
Layout:=ppLayoutTitle

ActiveWindow.View.GotoSlide currSlide + 1

End Sub

Best regards
Martin

P.S. I know the "Select Case" at the beginning is weird, but of course
I tried

If ActiveWindow.ActivePane.ViewType <> 1 Or 7 Or 11 Then
Exit Sub
End If

.... which just didn't work ... very odd...
 
Thanks again, Steve for saving me hours trying get the cursor position
from the thumbnail view.

<g> And thank YOU for posting the result.

Nothing weird about the Case statement, IMO. The ability to do just this is
one of the things that makes Case *so* handy in .. um ... I hesitate to say it
... cases like this.
 
Back
Top