Andrzej Sawula wrote:

Ave,

I recorded what I supposed to be a very straightforward macro:

sub insertHereBookmark

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Bookmark"
args1(0).Value = "here"

dispatcher.executeDispatch(document, ".uno:DeleteBookmark", "", 0, args1())

dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Bookmark"
args2(0).Value = "here"

dispatcher.executeDispatch(document, ".uno:InsertBookmark", "", 0, args2())

end sub


It was supposed to delete the bookmark named "here" and then insert it at current cursor position - just a simple "last worked here" tag for me. Now, the problem is, it behaves a little different: it does not delete the bookmark, and creates a bookmark "hereX", where X are subsequent numbers. The same happens even if the bookmark "here" does not exist - bookmark "here1" is created, next time "here2" and so on.

Could somebody point out what I am doing wrong, please?
(My OOo version is 1.9.122, under WinXP.)

Without looking up the documented behavior, this sounds like a bug. You can accomplish this directly using the API

Sub InsertBookmark(sName$, Optional oDocToUse)
 Dim oBookMarks
 Dim oBookMark
 Dim oDoc
 Dim oCurs
 oDoc = IIF(IsMissing(oDocToUse), ThisComponent, oDocToUse)
 oBookMarks = oDoc.getBookMarks()
 If (oBookMarks.hasByName(sName)) Then
   oBookMark = oBookMarks.getByName(sName)
   oBookMark.dispose()
 End If
 oBookMark = oDoc.createInstance("com.sun.star.text.Bookmark")
 oBookMark.setName(sName)
 oCurs = oDoc.getCurrentController().getViewCursor()
 oDoc.getText().insertTextContent(oCurs, oBookmark, False)
End Sub

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw
My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm
Free Info:  http://www.pitonyak.org/oo.php


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to