printing and exiting from macro

T

timc

first let me say i know extremely little about programming. i have made a
macro in access that launches a mail merge document in word. after running
the macro, the output is printed and then word is to close the file and exit
back to access. here are my problems.

1. when i run the macro in word (run to printer) the printer dialogue box
shows up so i have to pick the printer to print to.
2. if i run the word macro to a new document and print, i get the dialogue
box that wants to know if i want to save the new file.
3. i then get an error message telling me that word is still printing and
cannot exit (the printing has already ended when i get this message.)

needless to say that having to deal with these issues makes automating my
process very difficult. if anyone out there know how do deal with these
please advise. much apprecaited.
 
J

Jezebel

Sounds like your macros were created using the macro recorder rather than by
reading the documentation.

1. To print the document to the active printer, use: doc.Printout

2. To use Word dialogs without being prompted for information, use the
methods of the Dialogs collection.

3. To close a document without being prompted to save, use doc.Close
SaveChanges:=False

All of these things are explained, simply, in the help files for the
respective keywords. To complain that you 'know extremely little about
programming', in this context, is like complaining that you know very little
about driving but your car keeps running into trees; can someone help with
the trees?
 
J

Jay Freedman

One further bit: To avoid the error message about "Word is still
printing", use the optional Background parameter in the .PrintOut
command:

doc.PrintOut Background:=False

That tells VBA that it has to wait until printing is complete before
it can go on to execute the next line of the macro. If you omit the
Background parameter, VBA assumes that it has its default value, which
is True. That allows the rest of the macro to continue to execute
while printing goes on "in the background", and since the next
instruction is to close the document, that's when the error message
appears.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top