Microsoft KB Archive/187637

{|
 * width="100%"|

WD: Recorded Macro to Mail Merge to Printer Requires SendKeys

 * }

Q187637

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows NT, version 6.0
 * Microsoft Word for Windows 95, versions 7.0, 7.0a

-

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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please see the following page on the World Wide Web:

"http://www.microsoft.com/partner/referral/" For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

"http://support.microsoft.com/directory/overview.asp"

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.