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("com.sun.star.text.textfield.GetReference") Then
         If IsEmpty(tF.Anchor.Cell) then
            Curs = tF.Anchor.getText.createTextCursorByRange(tF.Anchor)
         Else
            Curs = tF.Anchor.Cell.Text.createTextCursorByRange(tF.Anchor)
         End if

         Curs.collapseToStart()
         Curs.goRight(1,True)
         Curs.CharColor = RGB(2,50,150)         
      End If
  Loop
End Sub

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

Imprint RSS