To find and color a phrase in the text of a Word table cell, I do this:
Code: Select all | Expand
oTb:Item(n).Cell(x,y):Select()
oWrd:Selection.Find:Execute("MyText", .F., .T.)
oWrd:Selection.Range:HighLightColorIndex=CLR_RED
Code: Select all | Expand
oTb:Item(n).Cell(x,y):Select()
oWrd:Selection.Find:Execute("MyText", .F., .T.)
oWrd:Selection.Range:HighLightColorIndex=CLR_RED
Code: Select all | Expand
PROCEDURE ColorOccurrencesInTableCells()
LOCAL oWord, oTable, oCell, oRange
LOCAL n, x
oWord := CreateObject("Word.Application")
oWord:Visible := .T. // Optional: Make Word application visible
oTable := oWord:ActiveDocument:Tables(1) // Modify as needed
FOR n := 1 TO oTable:Rows:Count
FOR x := 1 TO oTable:Columns:Count
oCell := oTable:Cell(n, x)
oRange := oCell:Range
oRange:Collapse(0) // Start from the beginning of the cell
DO WHILE oRange:Find:Execute("MyText")
oRange:HighlightColorIndex := 6 // Red color index
oRange:Collapse(0) // Move to the end of found text
ENDDO
NEXT
NEXT
oRange := NIL
oWord:Visible := .F. // Hide Word application
oWord := NIL
RETURN