|
|
|
 |
How to do a mail merge to the printer using
VBA, without displaying the Print dialog
|
Or in the case of Word 2002, how to do the opposite!
Article contributed by Ibby and Dave Rado
In Word 97 and 2000, if you do a mail merge to the printer using:
ActiveDocument.MailMerge.Destination = wdSendToPrinter
... the Print dialog is displayed.
The only way to prevent that from happening is as follows:
ActiveDocument.MailMerge.Destination = wdSendToNewDocument
'The ActiveDocument is now the merged document,
'not the main document
ActiveDocument.PrintOut Background:=False
ActiveDocument.Close wdDoNotSaveChanges
In Word 2002, because of all the complaints, Microsoft changed the behaviour so
that ActiveDocument.MailMerge.Destination = wdSendToPrinter no longer displays
the Print dialog. But of course, some people want the dialog to be displayed,
so that the user can choose the printer, the page range, and so on; so in that
scenario, the workaround is similar to the above code:
ActiveDocument.MailMerge.Destination = wdSendToNewDocument
'The ActiveDocument is now the merged document,
'not the main document
Dialogs(wdDialogFilePrint).Show
ActiveDocument.Close wdDoNotSaveChanges
This change in behaviour also means that if you have some users with Word 2002, and
other users with earlier versions, you will either have to test for the version of
Word in use, and run different code depending on the version, or bite the
bullet and merge to a new document and print from there in all cases. (You can use
Application.Version to test which version if
Word is in use).
Maybe in the next version of Word, we might actually be given the choice,
with something like wdSendDirectToPrinter and wdSendToPrintDialog!
|