If I run the code below, I get a "BASIC runtime error. Incorrect property value." on the "IF Found THEN" line.

If I remove the REMs from the "Option Explicit" and "DIM Found" lines, the error moves up one line.

If I replace the "Doc = ThisComponent" line with "Doc = StarDesktop.CurrentComponent", I get a "BASIC runtime error. Property or method not found" on the "SearchDesc = Doc.createSearchDescriptor()" line.

This code is attached to an OpenOffice.org Writer form letter and is triggered by the Print Document event. Somehow it looks like ThisComponent is something other than what all the examples I've seen say it should be. Can anyone see what I'm doing wrong or suggest a method of debugging it?


REM  *****  BASIC                           *****
REM  *****  insert "Attn:" line when needed *****
REM  ********************************************
REM Option Explicit
Sub Main
Dim Doc As Object Dim Cursor As Object
   Dim SearchDesc    As Object
REM    Dim    Found        As    Boolean
   Doc         = ThisComponent
   SearchDesc    = Doc.createSearchDescriptor()
   SearchDesc.searchString            = "Dear"
   SearchDesc.searchCaseSensitive    = True
   SearchDesc.searchWords            = True
   SearchDesc.searchSimilarity        = False
   Found         = Doc.findFirst(SearchDesc)
   IF Found THEN
       Cursor    = Doc.Text.createTextCursor
       IF NOT isStartOfSentence() THEN
           gotoStartOfSentence(FALSE)
       END IF
       Cursor.String = "Attn:"
Doc.Text.insertControlCharacter(Cursor, 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