Recorded Macro to Print Merge to Printer Requires SendKeys

ID: Q187637


The information in this article applies to:


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

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/refguide/


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 sample macro merges to a new document, prints the document, and then closes the document:


Sub MAIN
   MailMergeToDoc
   FilePrint
   FileClose 2
End Sub 


Word 2.x

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 backward slashes (\) indicate the command is continued on the next line. Do not include the backward slashes in your macro.

For the macro to work correctly, you must insert the following command 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

Additional query words: appears automatic


Keywords          : kbprint kbdta kbdtacode wordnt kbmacroexample winword kbmerge ntword macword word6 winword2 word7 
Version           : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; winnt:6.0
Platform          : WINDOWS winnt 
Issue type        : kbhowto 

Last Reviewed: May 19, 1999