Here's my current code. It almost works except that I have to remove any previous insertions of "Attn:". As it stands, I'm getting a new Attn: line inserted each iteration. The code to remove the line is taken from page 124 of the BASIC Programmer's Guide but once again doesn't seem to work. :(

The idea here is that I search for and remove any existing "Attn:" paragraphs. According to the programmer's guide, ^ matches the start of a paragraph and $ matches the end. However, while the document (as it is being printed) is clearly being updated to include new paragraphs (containing Attn:), the search for ^Attn:$ never succeeds (verified by stepping through the code). Instead, I build up a long list of Attn: paragraphs. :(

I suspect the code can also be simplified, but all I could find in the programmer's guide was replaceAll for removing paragraphs.


REM  *****  BASIC                           *****
REM  *****  insert "Attn:" line when needed *****
REM  ********************************************
Sub Main
Dim Doc As Object Dim FoundAt As Object
   Dim    InsertPoint    As Object
   Dim SearchDesc    As Object
   Dim    ReplaceDesc    As Object
   Doc         = ThisComponent
   SearchDesc    = Doc.createSearchDescriptor()
   SearchDesc.searchString            = "^Attn:$"
   SearchDesc.searchCaseSensitive    = True
   SearchDesc.searchWords            = True
   SearchDesc.searchSimilarity        = False
   FoundAt        = Doc.findFirst(SearchDesc)
   IF NOT IsNull(FoundAt) THEN
       ReplaceDesc = Doc.createReplaceDescriptor()
       ReplaceDesc.SearchRegularExpression = True
       ReplaceDesc.SearchString = "^Attn:$"
       ReplaceDesc.ReplaceString = ""
       Doc.replaceAll(ReplaceDesc)
   END IF
   SearchDesc.searchString            = "Dear"
   FoundAt         = Doc.findFirst(SearchDesc)
   IF NOT IsNull(FoundAt) THEN
       InsertPoint     = Doc.Text.createTextCursorByRange(FoundAt)
       IF NOT InsertPoint.isStartOfSentence() THEN
           InsertPoint.gotoStartOfSentence(FALSE)
       END IF
       Doc.Text.insertString(InsertPoint, "Attn: ", False)
Doc.Text.insertControlCharacter(InsertPoint, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
   END IF
End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to