Excel code to Wait until Word finishes printing before closing

M

Mike Molyneaux

I'm using Excel 2000 & windows nt 4, sp6.

I'm using Excel to extract label info to a 'prn' file,
then opening a Word doc & merging 'prn' info, then
printing the merged document.

Works great - except that when I attempt to close the word
object, I get a message that Word is printing & closing
will stop the printing. Don't want that to happen, but I
also want to close Word from within Excel.

My question is: Is there a way to execute a loop to
determine when the print job has finished? Where do I put
the loop? Or this a needless worry?

Thanks - mike

Code:

Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")

With wordApp
.Documents.Open Filename:="1.doc", _

(formatting code)

.Application.PrintOut Filename:="1.doc", _

.activeDocument.Close

End With

wordApp.Quit
 
H

Henry

Mike,

Put in a delay of 10 seconds to allow printing to finish before closing the
doc.
(You may find 5 seconds is long enough. Experiment!)

Application.Wait Time + TimeValue("00:00:10")

HTH
Henry
 
D

Dave Peterson

This might not be an option for you, but I've turned off background printing in
MSWord.

Tools|Options|Print Tab|Uncheck background printing.

(I did it manually, but maybe you could have your macro do it (and reset it back
when you're done).)
 

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