Maybe someone here can help me. I posted the same question in two other (national) communities. I didn't get an answer yet.
I want to run an email mailmerge through a macro. When I run it manually with the wizard, everything works fine. But when I run my macro, it always just uses the first record in the database and ignores all further records. When I change the macro to file-output instead of sending emails, the macro works just fine. I don't get it.
Here is my Code:
Code: Select all
Sub MailMergeService
Dim mm as Object
mm = CreateUnoService("com.sun.star.text.MailMerge")
With mm
'Output file
' .OutputType = com.sun.star.text.MailMergeType.FILE
' .OutputUrl = "file:///home/peter/"
' .FileNamePrefix = "mm_"
' .SaveAsSingleFile=True
'Output email
.DocumentURL = "file:///home/peter/ppt.odt" 'writer document url
.OutputType = 3 'email output
.DataSourceName = "testdb" 'database name
.CommandType = 1 '1 = predefined query, 2 SQL
.Command = "abc" 'query name
.Subject = "testing subject"
.MailBody = "testing mailbody"
.AddressFromColumn = "email"
' .BlindCopiesTo= Array("x@x.xx")
.SendAsAttachment = 1
.AttachmentName = "xtest.pdf"
.AttachmentFilter = "writer_pdf_Export"
.execute(Array())
.dispose()
End With
MsgBox "emails sent" 'message macro finished
End Sub
thanks