Examples: EndInsert method
This agent iteratively prepends or appends paragraphs to an item, depending on user input. Insertions at the beginning require a paired BeginInsert and EndInsert.
Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Sub Initialize
Set session = New NotesSession
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
If dc.Count = 0 Then
Messagebox "No document selected",, "No doc"
Exit Sub
End If
Set doc = dc.GetFirstDocument
Set body = doc.GetFirstItem("Body")
Set rtnav = body.CreateNavigator
it$ = Inputbox$("Begin with ^ to prepend", _
"Enter text or blank to exit")
REM If Body item is empty, just append text
If it$ = "" Then Exit Sub
If body.Text = "" Then
If Left(it$, 1) = "^" Then it$ = Right(it$, Len(it$) - 1)
Call body.AppendText(it$)
it$ = Inputbox$( _
"Begin with ^ to put in front of last paragraph", _
"Enter text or blank to exit")
End If
While it$ <> ""
REM if ^, delete ^ and insert text before first paragraph
If Left(it$, 1) = "^" Then
it$ = Right(it$, Len(it$) - 1)
rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)
Call body.BeginInsert(rtnav)
Call body.AppendText(it$)
Call body.AddNewLine(1)
Call body.EndInsert
REM If no ^, append text to end of Body item
Else
Call body.AddNewLine(1)
Call body.AppendText(it$)
End If
it$ = Inputbox$( _
"Begin with ^ to put in front of last paragraph", _
"Enter text or blank to exit")
Wend
Call doc.Save(True, True)
End Sub