Word MailMerge and bypassing the Print dialog box

Word MailMerge and bypassing the Print dialog box

Post by HD » Thu, 08 Apr 2004 22:39:34


Hi,

I am doing a mail merge with Word and it works very well... as long as the
user clicks OK in the Print dialog box. How can I specify that not only I
want the Merge.Destination to be wdSendToPrinter, but I want it sent to the
printer without the dialog box opening. Here is my code:
oWord := CreateOLEObject('word.application');
oWord.Visible := false;
oWord.Documents.Open(wkFile);
oDocument := oWord.ActiveDocument;
oMerge := oDocument.MailMerge;
oMerge.MainDocumentType := wdFormLetters;
oMerge.OpenDataSource(p_DataSource);
oMerge.Destination := wdSendToPrinter
oMerge.MailAsAttachment := False;
oMerge.MailAddressFieldName := '';
oMerge.MailSubject := '';
oMerge.SuppressBlankLines := True;
oMerge.DataSource.FirstRecord := wdDefaultFirstRecord;
oMerge.DataSource.LastRecord := wdDefaultLastRecord;
oMerge.Execute(False);
// The Execute command is not finished executing that the Print dialog
box opens....

I found that the printing is being done with the Application.PrintOut...
but where would i put it?
Thanks in advance for any help.

HDumas
 
 
 

Word MailMerge and bypassing the Print dialog box

Post by kalyan » Thu, 08 Apr 2004 23:11:21

After mailmerge.execute if you add the following lines you can supress the
print dialog.



WordDoc.MailMerge.Execute(True);
WordApp.ActiveDocument.printout(True);
WordApp.ActiveDocument.Close(wdDoNotSaveChanges);




the
dialog