0

I have to write a macro that highlights specific numbers (to set the background color to yellow).

I have already written a macro that finds these numbers using object Cursor but i don't know how to change the background color.

Dim Cursor As Object
Dim Proceed As Boolean

Cursor = ThisComponent.Text.createTextCursor()
Cursor.gotoStart(False)

Do
    Cursor.gotoEndOfWord(True)

    'some If statements that check if the number is correct
        'Cursor.CharEmphasis = com.sun.star.text.FontEmphasis.DOT_BELOW
    Proceed = Cursor.gotoNextWord(False)        
Loop While Proceed

I found a function that emphasises the text with dots below the text. Is there something similar for highlighting the text?

Izak
  • 307
  • 5
  • 12

2 Answers2

2

You're looking for CharBackColor:

oCursor.CharBackColor = RGB(255,255,0)
Jim K
  • 12,824
  • 2
  • 22
  • 51
0

The following code will put yellow background at any cell with entry less than MY_MIN or more than MY_MAX in the cell range from col1 to col2 and row1 to row2.

For I = col1 To col2
 For J = row1 to row2
    Cell = Sheet.getCellByPosition(I,J)
    If Cell.Type <> com.sun.star.table.CellContentType.EMPTY Then
        If Cell.Value < MY_MIN Or Cell.Value > MY_MAX Then
            Cell.CellBackColor = RGB(200,200,0)
        End If
    End If
 Next J
Next I

Hope, this solves your problem.

Epaminondas
  • 818
  • 9
  • 14