Print and then close application

I

Ian

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 ([email protected])
 
J

Jean-Guy Marcil

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
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
I

Ian

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
 
J

Jean-Guy Marcil

Ian was telling us:
Ian nous racontait que :
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

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.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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