How do you know when printing has finished?

H

Henry

Word 2K running under WinXP.

I've got a command button on my Doc. with the code behind it as:

Me.Printout

Me.SaveAs ("filename") etc.

Application.Quit


The problem is that I'm printing to a network printer and the network can be
very slow at times.
It's only one page long, but I often get a messagebox popping up saying that
the printing hasn't finished and closing down word will cancel the print
job.
I've tried putting DoEvents at various places in the code and tried to use
Application.Wait (a valid Excel VBA command, but not valid in Word VBA) to
force a pause, all to no avail.

Any of you Word VBA gurus got an answer to this one?

TIA

Henry
 
J

Jay Freedman

Henry said:
Word 2K running under WinXP.

I've got a command button on my Doc. with the code behind it as:

Me.Printout

Me.SaveAs ("filename") etc.

Application.Quit


The problem is that I'm printing to a network printer and the network
can be very slow at times.
It's only one page long, but I often get a messagebox popping up
saying that the printing hasn't finished and closing down word will
cancel the print job.
I've tried putting DoEvents at various places in the code and tried
to use Application.Wait (a valid Excel VBA command, but not valid in
Word VBA) to force a pause, all to no avail.

Any of you Word VBA gurus got an answer to this one?

TIA

Henry

Change the .Printout line to

Me.PrintOut Background:=False

When you omit the optional Background parameter, its default value of True
means that Word should create a "background process" to send the document to
the print spooler, and immediately return control to the macro. By making it
False, you're saying to use the "foreground process"; that makes the macro
wait until the spooling is completed before executing the next line of the
macro.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
H

Helmut Weber

Hi Henry,

see help for: "application.backgroundprintingstatus", hopefully.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

Alex Ivanov

Keep in mind that checking Backgroundprintingstatus in some (rare) cases
causes infinite loop.
It never changes to 0, and may produce no printouts until you press
ctrl-break.
Neither doevents nor Sleep inside the loop helps, if this happens.
 
H

Henry

Jonathan West said:
You should take a look at this article

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


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Thanks all,

Jay's solution works just fine, thank you Jay.

I'll bear in mind Alex's warning, but it doesn't seem to be a problem ATM.

I went to your link, Jonathan, but it seems to say that 'Background:=False'
is the preferred way to do it.

Once again, thanks all.

Henry
 

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