-
Hi all,
I have a vb app that prints a list of word and excel documents.
The printing works just fine, but I need to know when Word and Excel has finished the print jobs I sent to them, in order to close the applications(word and excel).
If I use the Application.Quit methode, the users of my app sometimes get the message saying : "Word is currently printing. Quitting Word will cancel all pending print jobs........."
I don't want the users to see this message, but I have not found any other way of making sure that Word and Excel has shut down, than to use the Quit methode.
So, in order for me to use the Application.Quit, I need a way to determine if the print jobs has finished.
All suggestions are very very very welcome.
peet
-
Peet,
Try this, it's not the best solution but it should work. There is a property of the Word object you can interogate called backgroundPrintingStatus. This tells you how many jobs are being printed by the current printer. All the time this value is greater than 0 word is still printing. You could do something like this:-
Dim msWord as Word.Application
Set msWord = CreateObject("Word.Application.8")
'open a document and print it...
msWord.ActivePrinter = <your printer name goes here>
msWord.Documents.Open <your filename goes here>
msWord.PrintOut
msWord.ActiveDocument.Close False
'wait for printing to finish...
while msWord.backgroundPrintingStatus > 0
<do something here!>
wend
'now it's safe to quit
msWord.application.quit
set msWord = nothing
I tried putting a doEvents in the while loop but this seemed to slow down the printing. Have a play around with code and see if it helps. You might like to know there is also a property called backgroundsavingstatus which does the same when saving a file.
hope this helps
Mark Herring
Technical Support
Promark Software Ltd
[email protected]
-
Thank's
Thank you Mark,
your solution was excelent and it works just fine.
:)))
-
You're stuck waiting until the report is totally spooled. Try changing your print statement to this:
WordApp.ActiveDocument.PrintOut False, , , , , , , nActualCopies
This tells Word to wait until the report is generated before continuing.