Delphi Word automation - print a merged document

Currently, the My D5 application can send multi-member data to a Word document using:

wrdapp := CreateOleObjct(word.application); wrdDoc := wrdApp.Document.Open(TemplateLocation); wrdMailMerge := wrdDoc.MailMerge; populateMailMergeDateFile; wrdMailMerge.execute; 

and then

 wrdDoc.Saved := False; wrdDoc.Close(False); wrdApp.Visible := True; 

I would like to suggest the option of transferring the combined document directly to the printer. However, I cannot find the code that allows this to happen.

 wrdDoc.PrintOut; wrdDoc.Saved := False; wrdDoc.Close(False); 

Prints a template document without merged data.

 wrdDoc.Saved := False; wrdDoc.Close(False); wrdDoc.PrintOut; 

Displays an object variant error.

 wrdMailMerge.PrintOut; 

Displays automation errors.

I tried to use True instead of False. Can someone tell me how to print the combined document correctly?

thank you very much

+4
source share
1 answer

In my mailmerge code, I set MailMerge.Destination to wdSendToNewDocument before doing the merge, after which I call WordApplication.ActiveDocument.Printout.

+5
source

All Articles