4

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

Amro
  • 123,847
  • 25
  • 243
  • 454
notidaho
  • 588
  • 8
  • 28

1 Answers1

5

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

frogb
  • 2,040
  • 15
  • 22
  • yeah I had that MailMerge.Destination := wdSendToNewDocument before executing the merge. However it didn't make a difference to displaying the merge when it was removed. When I try printing the active document as you suggest it gives me "RPC server is unavaible" – notidaho Sep 30 '11 at 14:18
  • *edit* I was saving and closing the document before printing. It works! thanks frogb :) Can anyone tell me the significance of True and False in the save and close statements? – notidaho Sep 30 '11 at 14:25
  • @notidaho: You shouldn't use False or True in the Close method, you have to specify a wdSaveOption, see http://msdn.microsoft.com/en-us/library/bb238160%28office.12%29.aspx – The_Fox Sep 30 '11 at 14:33