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

Word .Printout problems 1

Status
Not open for further replies.

pflangan

Programmer
Jun 13, 2001
49
GB
Does anyone know how to wait for word to finish printing
before quitting the application.

I've got a button on a form that automatically prints out a word document, but at the moment I either get

1. A copy of WINWORD.exe is left running on the system when I don't use the objWord.application.Quit command or

2. Word pops up and asks me do i really want to quit and cancel all documents sent to the printer?

here's the code:

Dim objWord as Word.Application

Set objWord = New Word.Application
objWord.Documents.Open FileName:=sFilename
objWord.PrintOut , , , , , , , CInt(Me.txtBrief)
objWord.Documents.Close
objWord.Application.Quit
Set objWord = Nothing


Anyone got suggestions.
 
sorry, found the answer myself

oWord = CREATEOBJECT('Word.Application')
WITH oWord
.PrintOut()
WHILE .BackgroundPrintingStatus > 0
DOEVENTS() 'Make sure you leave the OS enough time to update

WEND
.Application.Quit(0) 'Quit, don't save and don't prompt
END with
 
Would you mind posting the full code here? I need to do the same thing from within Access: open a Word Doc, print, and quit Word. The code would save me time...thanks.
 
Lucky, I earmarked it for notification. anyway here's the code.


Dim objWord As Word.Application
Dim sFilename as string
sFilename = "C:\mydocument.doc"

Set objWord = New Word.Application
objWord.Documents.Open FileName:=sFilename
objWord.PrintOut , , , , , , , 1 ' the one is the number of copies required

While (objWord.BackgroundPrintingStatus > 0)
DoEvents
Wend
'i found this part on the microsoft site. it waits until printing has completed. if you try and quit word 'before it has completed printing it'll pop up and ask you are you sure you want to quit.
objWord.Documents.Close
objWord.Application.Quit
Set objWord = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top