fine tuning a goto bookmark libreoffice macro

573 views Asked by At

I have a libreoffice macro to go to a certain bookmark ("qui")

sub vai_qui
ViewCursor = ThisComponent.CurrentController.getviewCursor()
Bookmark = ThisComponent.Bookmarks.getByName("qui").Anchor
ViewCursor.gotorange(Bookmark, False)
end sub

The problems are two:

  1. this is a libreoffice macro, and so it runs also with Calc and Base, and I'd like to avoid error messages in Calc and Base;
  2. With this macro the cursor go to the bookmark, but the focus of Writer is not on the cursor: I prefer to avoid this situation and have focus on cursor.

Thank you

1

There are 1 answers

3
ngulam On

As you have been told on LibreOffice forum***:

  • avoid calling the macro, if you don't have a Writer document
  • check for the document type

    If NOT ThisComponent.supportsService("com.sun.star.text.TextDocument" ) Then
       Exit Sub  
    End If
    
  • check for bookmarks existence

    oBookmarks = ThisComponent.getBookmarks()  
    If NOT oBookmarks.hasByName("qui") Then
    

*** Cross-posting a question without any reference to other forums you asked for help is offending to the volunteers who spend their free time to help.