I has the following want to print cheque from a template and replace its variable, however the marign of print out is not the same as the template, I try to set the RichTextParagraphStyle, it still now work.
Sub PrintCheque()
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim fdoc As NotesDocument
Dim newdoc As NotesDocument
Dim dc As NotesDocumentCollection
Dim body As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtrange As NotesRichTextRange
Dim uidoc As NotesUIDocument
Dim searchString As String
Dim replaceString As String
Dim SearchList(4) As String
Dim i As Integer
Dim k As Integer
Dim n As Integer
SearchList(0) = "<<Date>>"
SearchList(1) = "<<Payee>>"
SearchList(2) = "<<Currency>>"
SearchList(3) = "<<Amount>>"
Set db = session.CurrentDatabase
Set uiview = ws.CurrentView
Set dc = uiview.Documents
If dc.Count = 0 Then
Dim msglist(0) As Variant
Call GetMessageHandler ("ACC00011", msglist)
Exit Sub
End If
Set doc = dc.GetFirstDocument
While Not (doc Is Nothing)
Dim bankname As String
bankname = doc.ChequeBankName(0)
Set fdoc = GetChequeFormat (bankname)
Set newdoc = New NotesDocument(db)
Call fdoc.CopyAllItems(newdoc,True)
If Not fdoc Is Nothing Then
Set body = newdoc.GetFirstItem("ChequeLayout")
'''Added by Mei 01
Dim rtpStyle As NotesrichTextParagraphStyle
Set rtpStyle = session.CreateRichTextParagraphStyle
rtpStyle.FirstLineLeftMargin = RULER_ONE_INCH* 0.75
rtpStyle.LeftMargin = RULER_ONE_INCH* 0.75
Call body.AppendParagraphStyle(rtpStyle)
'''''01
Set rtnav = body.CreateNavigator
If rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then
count% = 0
Do
count% = count% + 1
Loop While rtnav.FindNextElement
Else
newdoc.Form = "Cheque for Print"
Call newdoc.Save(True, True)
Exit Sub
End If
Set rtrange = body.CreateRange
n = 0
For k = count% To 1 Step -1
If Not rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, _
k) Then
Exit For
End If
Call rtrange.SetBegin(rtnav)
For i=0 To Ubound(SearchList)
searchString = SearchList(i)
replaceString = ReplaceChequeVariable(searchString,doc)
Call rtrange.SetBegin(rtnav)
While rtrange.FindAndReplace _
(searchString, replaceString, RT_FIND_CASEINSENSITIVE)
Set rtrange = body.CreateRange
Call rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, k)
Call rtrange.SetBegin(rtnav)
n = n + 1
Wend
Set rtrange = body.CreateRange
Call rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, k)
Call rtrange.SetBegin(rtnav)
Next
Next
End If
If n > 0 Then
Call body.Compact
End If
newdoc.Form = "Cheque for Print"
Set uidoc = ws.EditDocument(False, newdoc)
'Set uidoc = ws.EditDocument(True,newdoc)
'Call uidoc.Print
Set doc = dc.GetNextDocument(doc)
Wend
End Sub