Ask Your Question

writer macro to go to a bookmark

asked 2017-09-12 20:13:50 +0200

fbertoldi gravatar image

There is a way to write a (Libre Writer) macro to go to a certain bookmark? (registering it's not possible) Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-09-12 22:59:36 +0200

komma4 gravatar image

Yes,,, depending on what you mean to "go to" a bookmark.

SUB jump2Bookmark(s)
' pass the name of the bookmark
' to scroll to bookmark
ViewCursor = ThisComponent.CurrentController.getviewCursor()
Bookmark = .ThisComponent.Bookmarks.getByName(s).Anchor
ViewCursor.gotorange(Bookmark, False)

Does this answer your question, already? Anyway, if you want to manipulate a boolmark's content... this should show you how to access it ;-)

edit flag offensive delete link more


Thank you. It seems work. I will do more tests.

fbertoldi gravatar imagefbertoldi ( 2017-09-13 17:11:15 +0200 )edit

Does not completely works if (Bookmark, False) : no focus on cursor; for some aspects better (fucus on cursor) if (Bookmark, True). To work I have to move the cursor, so focus on cursor. The problems are the non writer apps: Calc, Dbase: I get always an error message :( This is the macro: " sub vai_qui
ViewCursor = ThisComponent.CurrentController.getviewCursor()
Bookmark = ThisComponent.Bookmarks.getByName("qui").Anchor
ViewCursor.gotorange(Bookmark, False)

fbertoldi gravatar imagefbertoldi ( 2017-09-13 17:43:21 +0200 )edit

Thank you, komma4. Now I need some code to : 1) focus on cursor; 2) avoid error message in Calc and in Base. This second thing: is not possible an "if" command (if there is "qui" bookmark, then ... your macro)

fbertoldi gravatar imagefbertoldi ( 2017-09-13 19:35:31 +0200 )edit

To avoid error messages on other modules of LO than Writer: * don't call the macro from any other document than a Writer in the first place :-)
* check for supportsService;

If NOT ThisComponent.supportsService(_
   "" ) Then
   Exit Sub
End If
  • check for exsitance of a bookmark

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

Get MRI extension and generate / write your code

komma4 gravatar imagekomma4 ( 2017-09-13 21:21:57 +0200 )edit

Thank you, komma4. Remains only the problem of focus :(

fbertoldi gravatar imagefbertoldi ( 2017-09-14 13:16:04 +0200 )edit

Solution of the focus problem: if I re-do the macro, it's all OK. So I duplicate, I repeat the instructions 2 times, and so it works!

fbertoldi gravatar imagefbertoldi ( 2017-09-14 15:22:28 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-09-12 20:13:50 +0200

Seen: 17 times

Last updated: Sep 12