So my problem is that I’ve got a number of icons on a custom toolbar a couple of which simply move the cursor to a bookmark in the Writer document. Each of the icons invoke a macro that passes the name of the bookmark to go to to this Sub:
Sub GoToNamedBookmark(BookmarkName)
Dim ViewCursor, AllBookmarks, BookmarkAnchor As Object
' We first check to see if the desired bookmark exists
AllBookmarks = ThisComponent.getBookmarks()
If NOT AllBookmarks.hasByName(BookmarkName) Then
MsgBox("The bookmark" + BookmarkName + " does not exist!", 16, "GoToNamedBookmark")
Exit Sub
End If
' At this point we can try to move the ViewCursor to the Bookmark
ViewCursor = ThisComponent.CurrentController.getviewCursor()
BookmarkAnchor = ThisComponent.Bookmarks.getByName(BookmarkName).Anchor
ViewCursor.gotorange(BookmarkAnchor, False)
End Sub
It all works properly so long as the cursor is inside the main document window. But I get a runtime error – on the very last line – if the cursor is inside an actual comment box, also called an annotation.
So what I need is a way to determine if the cursor is actually inside a comment box, and how to give the main document the focus again. (I’m assuming that is the real problem here.)