notidaho
notidaho

Reputation: 588

Delphi Word automation - print merged document

My D5 application can currently mail merge multiple members 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 offer the option of passing the merged document straight to the printer. However I cannot find the code which allows this to happen

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

Prints out the template document with no merged data.

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

Displays a variant object error.

wrdMailMerge.PrintOut;

Displays an automation errors.

I've tried using True instead of False as well. Can anybody advise me as to how to print the merged document correctly?

many thanks

Upvotes: 4

Views: 2157

Answers (1)

frogb
frogb

Reputation: 2060

In my mailmerge code, I set MailMerge.Destination to wdSendToNewDocument before executing the merge, then afterwards I call WordApplication.ActiveDocument.Printout.

Upvotes: 5

Related Questions