Is it possible in Basic to put into a variable current value of the “Find” field. For example:
I’m writing a macro that appends to each occurrence of a word in a cell a string “<–” to mark it. "word"
in the example below is hard-coded to the target
variable, but perhaps there is some way to extract it from the “Find” field dynamically?
Sub findAndMark
Const toAppend = " <--"
Const target = "word"
Set oRange = ThisComponent.CurrentSelection
For i = 0 To oRange.Rows.getCount() - 1
For j = 0 To oRange.Columns.getCount() - 1
Set cell = oRange.getCellByPosition( j, i )
tc = cell.CreateTextCursorByRange(cell.Start)
pointPos = InStr(cell.String, target)
If pointPos>0 Then
tc.goRight(pointPos - 1, False)
tc.goRight(Len(target), True)
cell.insertString(tc, toAppend, False)
EndIf
Next
Next
End Sub
Heavily based on this answer in another thread