I has the following code to find and replace the content of rich text:
Set body = newdoc.GetFirstItem("Content")
Set rtnav = body.CreateNavigator
If rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then
count% = 0
Do
count% = count% + 1
Loop While rtnav.FindNextElement
’ Else
’ newdoc.Form = “Cheque for Print”
’ Call newdoc.Save(True, True)
’ Exit Sub
End If
Set rtrange = body.CreateRange
n = 0
For k = count% To 1 Step -1
If Not rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, _
k) Then
Exit For
End If
Call rtrange.SetBegin(rtnav)
For i=0 To Ubound(SearchList)
searchString = SearchList(i)
replaceString = ReplaceLetterFormatVariable(searchString,ReplaceList)
Call rtrange.SetBegin(rtnav)
While rtrange.FindAndReplace _
(searchString, replaceString, RT_FIND_CASEINSENSITIVE)
Set rtrange = body.CreateRange
Call rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, k)
Call rtrange.SetBegin(rtnav)
'Call rtrange.SetStyle(rtpStyle)
n = n + 1
Wend
Set rtrange = body.CreateRange
Call rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, k)
Call rtrange.SetBegin(rtnav)
'Call rtrange.SetStyle(rtpStyle)
Next
Next
’ End If
If n > 0 Then
Call body.Compact
End If
It works fine. If the content contains image, the image disappear after find and replace. How can I do?