Recorded Macro to Print Merge to Printer Requires SendKeys

Last reviewed: July 30, 1997
Article ID: Q74913
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word 97 for Windows

SUMMARY

In order to use a macro to send a merged a document directly to the printer, the macro must include the SendKeys macro command. Without the SendKeys macro command, the Print dialog box remains on the screen.

MORE INFORMATION

Visual Basic for Applications

Add a SendKeys statement to send the {enter} key to the Print dialog box. The SendKeys statement should precede the Mail Merge statements, as in the following Visual Basic for Applications example;

   Sub MergeAndPrint()
      SendKeys "{enter}"
      With ActiveDocument.MailMerge
         .Destination = wdSendToPrinter
         .Execute
      End With
   End Sub

If you don't need to send the document directly to the printer, you can merge it to a new document and then print it. The following sample Visual Basic for Applications macro merges to a new document and prints the document:

   Sub MergeToDocAndPrint()
      With ActiveDocument.MailMerge
         .Destination = wdSendToNewDocument
         .Execute
      End With
      ActiveDocument.PrintOut
   End Sub

WordBasic

Word 6.x, 7.x:

Add a SendKeys statement to send the {enter} key to the Print dialog box. The SendKeys statement should precede the MailMergeToPrinter statement as in the following example.

   Sub MAIN
      SendKeys "{enter}"
      MailMergeToPrinter
   End Sub

If you don't need to send the document directly to the printer, you can merge it to a new document and then print it. The following example macro merges to a new document, prints the document, and then closes the document:

   Sub MAIN
      MailMergeToDoc
      FilePrint
      FileClose 2
   End Sub

Word 2.0:

If a macro is recorded to merge a document to the printer, the macro has the following commands (there may be different values for the parameters, depending on your choices in the dialog boxes):

   Sub MAIN
      FilePrintMerge .MERGERECORDS = 0, .From = "", \
      .To = "", .PRINT
      FilePrint .Type = 0, .NumCopies = "1", .Range = 0,\
      .From = "", .To = "", .Reverse = 0, .Draft = 0,\
      .UpdateFields = 0, .PaperFeed = 8, .Summary = 0, \
      .Annotations = 0, .ShowHidden = 0, .ShowCodes = 0,\
      .FileName = ""
   End Sub

NOTE: The backslashes (\) indicate the command is continued on the next line. Do not include the backslashes in your macro.

For the macro to work correctly, the following command must be inserted before the FilePrintMerge command:

   SendKeys "{enter}", -1

Multiple Copies:

If you want to print more than one copy of your merged document, use the following SendKeys command to modify the Copies box in the Print dialog box:

   SendKeys "N{ENTER}", -1

NOTE: "N" is the number of copies you want to print.

REFERENCES

"Microsoft Word for Windows Technical Reference," pages 88-90 "Microsoft Word for Windows and OS/2 Technical Reference," pages 251-253

Kbcategory: kbusage kbmacro KBSubcategory: kbmerge


Additional query words: 1.x 2.0 word6 winword 2.0a 2.0a-CD 1.x
appears automatic 6.0 6.0a 6.0c winword2 word95 word7 word8 word97 8.0
8.0 vb vba vbe
Keywords : kbmerge
Version : 1.x 2.x 6.0 6.0a 6.0c 7.0 7.
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.