Macro cannot add annotation to same sheet


I have a problem which I don’t know if it’s a bug or if I just made some error in the code.

Function AddAnnotation(annotation as String, s as integer, r as integer, c as integer)
    Sheets = ThisComponent.Sheets
    Sheet = Sheets.getByIndex(s-1)
    Annotations = Sheet.getAnnotations()
    Cell = Sheet.getCellByPosition(c, r)
    CellAddr = Cell.CellAddress
    Annotations.insertNew(CellAddr, annotation)
    Cell.Annotation.isVisible = True
End Function

This macro add an annotation to a cell specified by s, r and c. It work perfectly fine if the targeted cell is on another sheet than the one where the macro was called from but if you call it to the same one then it doesn’t do anything.
For example: If I call =AddAnnotation("TEST"; 2; 1; 1) from a cell on the first sheet it’ll work and add an annotation to the second sheet cell “B2” but if i call the same code from a cell on the second sheet it won’t work.

I’m on Windows 7 and this problem exist at least on OpenOffice 4.1.2 and LibreOffice

Any suggestions?


You are calling the Function as “User-defined-Function” out from a cell in Calc!?

Calc locks the entire sheet meanwhile Formula-calculations.

Yes, i can´t call it differently because i want to be able to change parameters on the fly using information from cells. Is there a way to circumvent this locking?

Edit: I’ve checked if the Document, sheet or cell were locked using isActionLocked() or protected with isProtected() but no.