Text annotations are a special type of text fields, therefore, in order to insert and remove annotations you must proceed in the same manner as for other kind of text contents
See the example below:
The first routine shows how to add an annotation
The second shows how to find and remove all annotations in a document
REM ***** BASIC *****
Sub Example_InsertAnnotation
oDoc = ThisComponent
oTextCursor = oDoc.Text.createTextCursor
oTextCursor.goToEnd(False)
Dim oDate As New {@see com.sun.star.util.Date}
With oDate
.Day = Day(Now)
.Month = Month(Now)
.Year = Year(Now)
End With
oTextAnnotation = oDoc.createInstance("{@see com.sun.star.text.TextField.Annotation}")
With oTextAnnotation
.Content = "Paolo was here!!"
.Author = "PM"
.Date = oDate
End With
oDoc.Text.insertTextContent( oTextCursor, oTextAnnotation, True)
End Sub
Sub Example_RemoveAllAnnotations
oDoc = ThisComponent
oEnum = oDoc.TextFields.createEnumeration
Do While oEnum.hasMoreElements
oTField = oEnum.nextElement
If oTField.supportsService("{@see com.sun.star.text.TextField.Annotation}") Then
MsgBox oTField.Content, 16,"Annotation detected!!"
oDoc.Text.removeTextContent(oTField)
MsgBox "Annotation Removed!!"
End If
Loop
End Sub