fine tuning a goto bookmark libreoffice macro

柔情痞子 提交于 2019-12-11 17:04:47

问题


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:


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.



来源:https://stackoverflow.com/questions/46204381/fine-tuning-a-goto-bookmark-libreoffice-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!