Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print and then close application

45 views
Skip to first unread message

Ian

unread,
Feb 17, 2005, 11:03:00 AM2/17/05
to
Hello, I wonder if anyone can help with this problem.

I'm using the following code to try and print a document and then shut
Word:

Application.PrintOut Copies:=1
Application.Quit (no)

If I put breakpoints on the code and step through it, then the
document prints and then Word closes down without saving, exactly as I
would expect it to.

However, if I run the code straight off, it doesn't print. I have
tried pausing for up to 20 seconds between the two commands (in case
the quick shut down was preventing the document from spooling
properly), but I still get no joy. I get the printer icon OK in my
system tray and the document is said to be spooling, but then it goes
without being printed.

This is part of a much larger set of code including table editing
followed by mailmerge (from Excel source), but I have isolated this
code as the problem.

Using in a blank document with just these two lines of code creates
the same problem as when it forms the final part of a much longer
script.

Has anyone got any tips as to how I can print and then close the
session of word. It is pretty vital that I close the session of word.

For anyone interested, the full script is as below (referred to macros
excepted, which are not of relevance to the problem)

=====
Me.Hide 'hides form
Macros.format 'takes out spurious lines in table
Macros.Mergedoc 'mailmerges
Application.PrintOut Copies:=1 'prints merged doc
ActiveWindow.Close (no) ' closes merged doc "Form Letters1"
Application.Quit (no) 'closes word (and template doc)
======

Thanks in advance, Ian (i...@stitch441.freeserve.co.uk)

Jean-Guy Marcil

unread,
Feb 17, 2005, 11:16:53 AM2/17/05
to
Ian was telling us:
Ian nous racontait que :

> Hello, I wonder if anyone can help with this problem.
>
> I'm using the following code to try and print a document and then shut
> Word:
>
> Application.PrintOut Copies:=1
> Application.Quit (no)
>
> If I put breakpoints on the code and step through it, then the
> document prints and then Word closes down without saving, exactly as I
> would expect it to.
>
> However, if I run the code straight off, it doesn't print. I have
> tried pausing for up to 20 seconds between the two commands (in case
> the quick shut down was preventing the document from spooling
> properly), but I still get no joy. I get the printer icon OK in my
> system tray and the document is said to be spooling, but then it goes
> without being printed.
>

Have you tried sandwiching the code like so to turn off background printing:

Dim tmp As Boolean

'Save actual value
Temp = Options.PrintBackground

'set it to false
Options.PrintBackground = False

ActiveDocument.PrintOut

'Restore original value
Options.PrintBackground = Temp

Application.Quit wdDoNotSaveChanges

Does that help?
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarci...@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Ian

unread,
Feb 23, 2005, 7:39:00 AM2/23/05
to
Options.PrintBackground = False
Application.PrintOut Copies:=1
Options.PrintBackground = True
Application.Quit (no)

Seems to work fine.

Thanks to those who offered help.

Cheers, Ian

Jean-Guy Marcil

unread,
Feb 23, 2005, 9:09:12 AM2/23/05
to
Ian was telling us:
Ian nous racontait que :

> Options.PrintBackground = False

You should use something similar to the code I suggested. The difference is
that your code will always reset the Background printing to True. I know
some people who need it to be false. My code leaves the user' options set as
they were.
In general, when dealing with user options, always check what state they are
in, do what you have to do, and then reset them to their original state.

0 new messages