Gary Dale wrote:
Sorry if this is pretty basic but I'm trying to print a form letter
and I wanted to customize it a little based on the values of the data
in the mailing list. If a field contains a value, I add an "attn:"
line if I have a name or a title to send to the attention of.
The macro is assigned to the Print Document event, which seems to be
correct because it is getting called once per database record - and
failing each time with the same error.
Anyway, below is my code - it's failing on the "IF Found THEN" line
with a "BASIC runtime error. Incorrect property value" error.
The idea, as I said, is straightforward: search for the word "Dear"
which starts the letter, then add an "Attn:" paragraph above it if
there is someone it should be directed to. I'm just trying to get the
adding of the "Attn:" working with this code. I'll add the fields
later if I can get this working. :)
Any hints?
Sub Main
Dim Doc As Object Dim Cursor As Object
Dim SearchDesc As Object
Doc = StarDesktop.CurrentComponent
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 Doc.Text.isStartOfSentence() THEN
Doc.Text.gotoStartOfSentence(FALSE)
END IF
Cursor.String = "Attn:"
Doc.Text.insertControlCharacter(Cursor,
com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False) END IF
END IF
End Sub
What happens if you run this instead?
Sub Main
Dim Doc As Object Dim Cursor As Object
Dim SearchDesc As Object
Doc = StarDesktop.CurrentComponent
SearchDesc = Doc.createSearchDescriptor()
SearchDesc.searchString = "Dear"
SearchDesc.searchCaseSensitive = True
SearchDesc.searchWords = True
SearchDesc.searchSimilarity = False
Found = Doc.findFirst(SearchDesc)
IF Found THEN
REM I am a comment so we do nothing
END IF
End Sub
What happens if you place a line as:
Option Explicit
As one of the first lines in the file (a line by itself before any
variables or subroutines are defined)?
I have some more thoughts, but I really need to go to sleep now.
I am interested in what you are doing. I have some comments related to
using the standard document Text object, it does not strike me as safe,
but I must explain that later.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]