How to change the color by search and replace in a basic macro

I want to change the color from specific text with find and replace in a macro. I tried that with “record macro”, but in this mode, the colorchance is not recorded.

So, what do i have to put into the macro for changing the color?

Here is how it looks until now.

sub rot_vokal
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "ָ"
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = "ָ"
args1(17).Name = "SearchItem.Command"
args1(17).Value = 3
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())


end sub

There is nothing which is worth to do by macro.

Do your Search and hit the find all button instead of replace all and set the Color, and your’e fine.

karolus is absolutely right - the easiest way to solve your problem is to find all “specific texts” and repaint it.

Sub runTest
	setColorToSpecificText("th", RGB(255,0,0)) ' Change all "th" to RED
End Sub

Sub setColorToSpecificText(sSpecificText As String, lColor As Long)
Dim oSrchDescr As Variant
Dim aFound As Variant
Dim oNextText As Variant
Dim i As Long
	oSrchDescr = ThisComponent.createSearchDescriptor()
	oSrchDescr.setSearchString(sSpecificText)
	aFound = ThisComponent.findAll(oSrchDescr)
	For i = 0 To aFound.getCount() - 1
		oNextText = aFound.getByIndex(i)
		oNextText.CharColor = lColor
	Next i
End Sub