Word automation with VB6

H

Harlan

I am using the following code in a VB6 project to provide a report. How can
I eliminate the message box that pops up stating "Word is currently
printing. Quitting Word will cancel all pending print jobs. Do you want to
quit Word?"

Thanks
Harlan



Dim moWordApp As Word.application
Dim moWordDoc As Word.document
Set moWordApp = New Word.application
moWordApp.Visible = False
With moWordApp

Set moWordDoc = moWordApp.Documents.Add("MLP-CGP-150")
With moWordDoc
.FormFields("text1").Result = ID
.FormFields("text2").Result = Range
End With
moWordDoc.PrintOut
moWordDoc.Close (False)
..Quit
End With

Set moWordDoc = Nothing
Set moWordApp = Nothing
 
J

Jonathan West

Hi harlan

Change this line

moWordDoc.PrintOut

to this

moWordDoc.PrintOut Background:=False

That will ensure that the next line of code doesn't execute until the whole
file has been sent to the print queue.

For more on this take a look at the following article

How to find out whether Word has finished printing
http://www.mvps.org/word/FAQs/MacrosVBA/WaitForPrint.htm
 
H

Harlan

Jonathan,
THANKS....not only did that solve my first problem, but it solved my next
one also...I was trying to figure out how to keep the user from closing out
my application before Word was finished spooling....
Again, thanks
Harlan
 

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