Closing Word Programatically

P

Pete Ocasio

I have the following snippet of code that works to print a documet
programatically to a Amyuni PDF Converter Printer. The problem is that
while the doc prints fine, the app hangs on the wordApp.Quit() call since
the call to quit is ambiguous across the classe word.application and
word.application.events2. Also,Word, the app, is running in the task
manager and consuming precious memory. Since I added the call to Quit(),
the interface becomes visible to the user after the printing is completed.
This was not happening before and I must ensure that visibility is supress.
Does anybody has any idea on how to tackle this two issues? That is
suppressing visibility of the program interface and closing the program so
the memory resources are free and returned to the OS.
Dim wordApp As New Word.Application()

Dim Documents As Word.Documents

Documents = wordApp.Documents

Documents.Open(RptFile, False, True)

wordApp.ActivePrinter = "crPrinter"

wordApp.PrintOut(False)

Documents.Close()

wordApp.Quit()

Thanks for your help.
 
P

Pete Ocasio

Thanks for taking the time to answer. VB.NET. Thanks of the tip on
Documents, I will change it.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Pete Ocasio > écrivait :
In this message, < Pete Ocasio > wrote:

|| I have the following snippet of code that works to print a documet
|| programatically to a Amyuni PDF Converter Printer. The problem is that
|| while the doc prints fine, the app hangs on the wordApp.Quit() call since
|| the call to quit is ambiguous across the classe word.application and
|| word.application.events2. Also,Word, the app, is running in the task
|| manager and consuming precious memory. Since I added the call to Quit(),
|| the interface becomes visible to the user after the printing is
completed.
|| This was not happening before and I must ensure that visibility is
supress.
|| Does anybody has any idea on how to tackle this two issues? That is
|| suppressing visibility of the program interface and closing the program
so
|| the memory resources are free and returned to the OS.
|| Dim wordApp As New Word.Application()
||
|| Dim Documents As Word.Documents
||
|| Documents = wordApp.Documents
||
|| Documents.Open(RptFile, False, True)
||
|| wordApp.ActivePrinter = "crPrinter"
||
|| wordApp.PrintOut(False)
||
|| Documents.Close()
||
|| wordApp.Quit()
||
|| Thanks for your help.

Where is your code being executed from?
(I am asking because it is relevant and because I am not sure why you all
those "()" all over the place... maybe it is a requirement?)

Also, you are using a variable called "Documents" which is a bad idea as it
is the name of an existing property in the Word object library. For what you
are doing, normally, from VBA or VB you could use something like:

'_______________________________________
Dim wordApp As New Word.Application
Dim MyDoc As Document

With wordApp
.ActivePrinter = "crPrinter"
Set MyDoc = .Documents.Open(RptFile, False, True)
With MyDoc
.PrintOut False
.Close wdDoNotSaveChanges
End With
.Quit
End With
'_______________________________________

Depending on where your code is being executed from, you might have to
change the parameter "wdDoNotSaveChanges" to its numerical constant: "0"

--
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