We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

writer macro to go to a bookmark [closed]

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 reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-15 10:54:26.996689

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(_
   "com.sun.star.text.TextDocument" ) 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

The solution of komma4 does not work properly with the new release of LibreOffice (Version: Build ID: 1:5.4.1-0ubuntu1 - CPU threads: 4; OS: Linux 4.13; UI render: default; VCL: kde4; Locale: it-IT (en_US.UTF-8); Calc: group). I get an error message: "BASIC runtime error. Property or method not found: supportsService" Could you help me?

fbertoldi gravatar imagefbertoldi ( 2017-10-24 09:57:47 +0200 )edit

As stated above: this is a macro for WRITER.
CALC doesn't have bookmarks.
In case I you tried in WRITER ("Calc: group" in your version information): which statement is highlighted, as the error occurs?

komma4 gravatar imagekomma4 ( 2017-10-24 20:45:03 +0200 )edit

Thank you. I know this is a writer macro, and in effect in writer it works well; but not in base, after upgrade to kubuntu 17.10. In Librebase (not in LibreCalc, strange) I get that error message :(. in the current version of LibreOffice it seems that supportService is not recognized in LibreBase.

fbertoldi gravatar imagefbertoldi ( 2017-10-26 16:53:23 +0200 )edit

I tried a temporary workaround: created an empty macro with the same name ("vai_qui") in the odb file I open often, and set macro security level to "low" (I know: not recommended). But don't works.

fbertoldi gravatar imagefbertoldi ( 2017-10-27 10:22:07 +0200 )edit

Question Tools

1 follower


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

Seen: 748 times

Last updated: Sep 12 '17