I have only one problem. No matter where in the document I invoke the macro, it returns the first Annotation of the document, then the last, second-last, third-last etc. Is there any way to make it return the Annotations either in ascending or descending order? This would obviate having to write some code to handle the "out of place" first Annotation.
For the present I display the Annotation contents using a messagebox. When (if) I have their retrieval in sequential order, either ascending or descending, I will do further processing with the contents.
Code: Select all
Sub ListAnnotes
Rem Report the content of all Annotations in a Writer document
Dim oDoc as Object
Dim oEnum as Object
Dim oField as Object
Dim oText as String ' do not Dim as Object or Variant
oDoc = ThisComponent
oEnum = oDoc.getTextFields().createEnumeration()
If Not IsNull(oEnum) Then
Do While oEnum.hasMoreElements()
oField = oEnum.nextElement()
If oField.supportsService("com.sun.star.text.TextField.Annotation") Then
oText = oField.Content
Msgbox "Annotation content is : " + oText
End If
Loop
End If
End Sub 'ListAnnotes