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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you close word after printer finish or find printer status? 5

Status
Not open for further replies.

ITdev

Programmer
Aug 6, 2001
25
US
Hi, I am trying to quit a newly created word document after setting the document to print. Problem is that I get a error message that the print will cancel if I close the word document.

How do I code it where I can close the word document after the print end? Here's a sample of my code...


wrdApp.ActiveDocument.PrintOut
wrdDoc.Saved = False

'tried putting a timer here but it won't work if the document is queue

wrdApp.Quit

Thanks in advance.
 
you can create a timer and occasionally query the word:

if wrdApp.BackgroundPrintingStatus = 0 then wrdApp.Quit

or(not the best way):
...
wrdApp.ActiveDocument.PrintOut
Application.Visible = False 'hide app
While wrdApp.BackgroundPrintingStatus > 0
DoEvents
Wend
wrdDoc.Saved = False
wrdApp.Quit
....


ide
 
Awesome.. exactly what I was looking for!

Thanks a million.
 
If you are not going to do anything until the document is finished spooling to the print queue (printing), set background=false. Use On error to intercept any errors.
Code:
    Dim lngErr as long
    Dim strErr as string
    on error resume next
        wrdApp.ActiveDocument.PrintOut false ' Wait for spooling
        lngErr = Err.Number
        strErr = Err.Description
    on error goto 0
    if lngErr <> 0 then
        msgbox strDescription
    End if
    wrdApp.Quit false ' no save
    Set wrdApp = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top