NotesRichTextRange.FindAndReplace Problem and notesRichTextNavigator.FindNextElement

I am taking wysiwyg content (Formatted Rich Text that I allow Domino to render as HTML over the web) that is currently found in Notes documents and I am trying to replace rich text content with same text wrapped with tags that reference styles. I then plan on striping the text of all of its formatting that I can just pass the html through to the web. This code works perfectly fine in displaying the different paragraph text and the font size, color and whether it is bold yet when I do the find and replace the code stops working @ “Loop While rtnavPara.FindNextElement(RTELEM_TYPE_TEXTRUN)”. I get the error… “Position is not valid”. Does anyone know why or how to resolve this? I’ve tried resetting the position in the “NotesRichTextRange” but no luck. Can someone help out here?

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim body As NotesRichTextItem

Dim objitem As NotesRichTextItem

Dim rtnavBody As NotesRichTextNavigator

Dim rtnavPara As NotesRichTextNavigator

Dim rtrangePara As NotesRichTextRange

Dim rtrangeRun As NotesRichTextRange

Dim paraCount As Integer

Dim runCount As Integer

Dim stylecolor As Integer

Dim stylesize As Integer

Dim stylebold As Integer



Dim style As NotesRichTextStyle



Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

Set body = doc.GetFirstItem("Body")

REM Get first paragraph in Body item

REM Set range and navigator for it

Set rtnavBody = body.CreateNavigator

If Not rtnavBody.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then

	Messagebox "Body item does not contain text,",, _

	"Error"

	Exit Sub

End If

Set rtrangePara = body.CreateRange







Set rtrangeRun = body.CreateRange

Do

	paraCount = paraCount + 1

	runCount = 0

	Call rtrangePara.SetBegin(rtnavBody)

	Call rtrangePara.SetEnd(rtnavBody)

	Set rtnavPara = rtrangePara.Navigator

REM Get each run in paragraph

REM Display it

	Call rtnavPara.FindFirstElement(RTELEM_TYPE_TEXTRUN)

	Set style = rtrangePara.Style

	Do

		runCount = runCount + 1

		Call rtrangeRun.SetBegin(rtnavPara)

		

		stylecolor = style.NotesColor

		stylesize = style.FontSize

		stylebold = style.Bold

		

		Messagebox rtrangeRun.TextRun,, _

		"Paragraph " & paraCount & ", Run " & runCount

		

		Messagebox "Color: "+Cstr(stylecolor)+" Size: "+Cstr(stylesize)+" Bold: "+Cstr(stylebold),,"color"

		Dim para As String

		para = rtrangeRun.TextRun

		para = |<span class="rob">|+para+|</span>|

		

		flag = rtrangeRun.FindAndReplace( rtrangeRun.TextRun , para )

		

		

		

		' Call doc.save(False, True)

		' Call rtrangePara.SetEnd(rtrangeRun)

		

		' Call doc.save(False, True)

		' Call rtrangePara.Reset( True, True )

		' Call rtrangePara.SetBegin(rtnavBody)

		

		Call rtnavPara.SetPosition( 2 )

		

	Loop While rtnavPara.FindNextElement(RTELEM_TYPE_TEXTRUN)

Loop While rtnavBody.FindNextElement(RTELEM_TYPE_TEXTPARAGRAPH) 

End Sub