Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Print and then close application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian - 17 Feb 2005 16:03 GMT
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 (ian@stitch441.freeserve.co.uk)
Jean-Guy Marcil - 17 Feb 2005 16:16 GMT
Ian was telling us:
Ian nous racontait que :

> Hello, I wonder if anyone can help with this problem.
>
[quoted text clipped - 14 lines]
> 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?
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Ian - 23 Feb 2005 12:39 GMT
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 - 23 Feb 2005 14:09 GMT
Ian was telling us:
Ian nous racontait que :

> Options.PrintBackground = False
> Application.PrintOut Copies:=1
[quoted text clipped - 6 lines]
>
> 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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.