Macro to change colour of some words in a string in a cell in Calc?

The results of a word search in a range in a LibreOffice Calc sheet are displayed on A1…A100 cells. Each cell may contain a paragraph of text within which there is the search result (somewhere). It’s sometimes hard to quickly see where the result is. How can one change the colour and weight only for the searched word not the entire cell?

Something like this: …[2014_10_15 order delivered ] [2014_10_13 received DK instruments] [2014_10_05 : DK order placed, payment…]

Thanks.

Of course, using a macro… :slight_smile:

Found a solution.
Here it is, in case anyone hits the same wall as I had :slight_smile:

Sub Main

Dim oDoc as Object, oSheet as Object, oCell as Object
Dim oTextCursor as Object
	oDoc=ThisComponent
	oSheet=oDoc.getSheets().getByindex(0)
	oCell=oSheet.getCellByPosition(0,1)
	oCell.String="The Moon is in synchronous rotation with Earth, always showing the same face with its near side marked by dark volcanic maria that fill between the bright ancient crustal highlands and the prominent impact craters. It is the second-brightest object in the sky, after the Sun (measured by illuminance on the surface of the Earth)"
	with oCell
		.CharFontName = "Arial"
		'.CharPosture = com.sun.star.awt.FontSlant.ITALIC
		.CharHeight=12		
	end with

str_length = len (oCell.String)

str_searched = "ea"
str_searched_length = len (str_searched)

oTextCursor = oCell.createTextCursor()
	
for i = 1 to str_length
	found = instr (i, oCell.String, str_searched)
	if found > 0 then
			With oTextCursor
				.gotoStart( False )
				.goRight(found-1 , False )  
				.goRight(str_searched_length, True )
				.setPropertyValue("CharColor",0099000)	
				.gotoEnd( False )
			End with
		i = i + found+str_searched_length
	endif
next i

End Sub