Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Mail Merge Object execute method

Status
Not open for further replies.

MikeHAdams

Programmer
Apr 13, 2002
1
US
I wrote a program that pulls data from various sources and creates a temporary table in an MBD file. I then open Word 2000 through code and open a Word document that has Mail Merge fields in it. I attach the MDB file as the datasource, set the Mail Merge Object to the SendToPrinter property and then invoke the "execute" method of the Word Mail Merge Object.

The problem is that when I invoke the "execute" method of the Mail Merge Object, a printer dialog box is opened and the user has to manually hit the "Ok" button to print the document. Since I am sending thousands of Word Mail Merged documents to the printer spool, it is unrealistic to require the user to manually hit the "Ok" button to print the currently active document each time it is displayed. I have tried unsuccessfully to use the Word "Dialogs" collection, the DoEvents function, and SendKeys statement. The problem seems to be that all flow of the program stop once the execute method is invoked, so no code is executed until after the print dialog box is closed.

I have little, to no experience sub-classing and hooking, which I believe is a solution to this problem. The other solution I though about but haven't tried is to created the Word objects with the "WithEvents" keyword. Is there anyway I can get the program to automatically print the document right after the Mail Merge "execute" method is invoked. Any solution, even sub-classing and hooking would be fine.
 
Have you tried creating a temporary document and then using Application.PrintOut? (rather than doing it all at once in the mailmerge). That works for me.

If the dialog is coming from your printer driver, then I would guess that you will need to find the window handle and send it a message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top