An OpenOffice/LibreOffice Macro to Colorize Internal References

Since I found no way to assign a character style to all „reference“ text fields of a document, to, for example have them colorized blue (indicating that they are links to some other place in the document) I had to write the following OOo BASIC macro to colorize them on the entire document

Sub ColorizeInternalReferences
   Set varEnum = thisComponent.getTextFields().createEnumeration()
   Set oDoc = ThisComponent
   Set oText = oDoc.Text

   Do While varEnum.hasMoreElements()
      tF = varEnum.nextElement()

      If tF.supportsService("") Then
         If IsEmpty(tF.Anchor.Cell) then
            Curs = tF.Anchor.getText.createTextCursorByRange(tF.Anchor)
            Curs = tF.Anchor.Cell.Text.createTextCursorByRange(tF.Anchor)
         End if

         Curs.CharColor = RGB(2,50,150)         
      End If
End Sub

This will turn all reference texts dark blue („RGB(2,150,200)“).