Dear list,
I am trying to update the text contained in a bookmark using a basic macro. It works great when I make a selection in the ui and insert a bookmark. This way the content is always replaced just as I would like. Trouble is when I position the cursor and then insert a bookmark. Now when I use the macro the text is always inserted at the position of the bookmark and never replaced. I cannot seem to figure out how to fix this.
This is the macro I use:
Dim Doc As Object
Dim Bookmark As Object
Dim Cursor As Object
Doc = ThisComponent
Bookmark = Doc.Bookmarks.getByName("bm1")
Cursor = Doc.Text.createTextCursorByRange(Bookmark.Anchor)
Cursor.String = "-- bookmark1 --"
Thanks a lot for you support!
- Koos
I half-remember coming across something like this before:
From section 14.11.1 Bookmarks in Andrew Pitonyaks OpenOffice Macros
Explained (http://www.pitonyak.org/OOME_3_0.pdf):
/A bookmark is text content that is accessible based on its name. A bookmark
may encompass a text range or a single point. Listing 371 inserts text
content at the point where a bookmark is anchored. Use the getString()
object method to obtain the string contained in the bookmark. Use
setString() to set the string contained in the bookmark. If the bookmark is
merely a point, the text is merely inserted before the bookmark. When a
created bookmark is inserted into the text, the insertion point determines
the bookmark’s anchor position./