Closing winword.exe in Code

  • Thread starter Thread starter CMAnderso
  • Start date Start date
C

CMAnderso

We have a access database that creates a Word Document using a template.
However when we the program completes it closes word as an application
but leaves winword.exe running as a process. In some cases winword.exe
will be listed multiple times. We have not had any luck closing the
winword.exe process with out doing so manually. Does anyone have any
ideas on how to accomplish this?

Thanks,
Cris
 
---------- CMAnderso said:
We have a access database that creates a Word Document using a template.
However when we the program completes it closes word as an application
but leaves winword.exe running as a process. In some cases winword.exe
will be listed multiple times. We have not had any luck closing the
winword.exe process with out doing so manually. Does anyone have any
ideas on how to accomplish this?

Cris,

when working with automation, you have to fully reference every object
in the automated app. So for ex if you have statements like:

Selection.SomeProperty = SomeValue

you'll have to write instead:

MyApp.Selection.SomeProperty = SomeValue

where MyApp is the Word app object you created with CreateObject.

If the objects are not fully referenced, a standard app instance will
be created which then runs parallel with MyApp and won't be closed
when MyApp is closed. There are some KB articles at MS about this, but
I don't have here the numbers.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
The problem is not trying to close ms-word,but really, the solution is make
sure your automation code uses the EXISTING copy of word in ram. I mean, way
load another copy in ram?

I would simply tell you to make sure you code closes word when done, but
when a user has to edit the word doc, then you really can't know when the
user is done. Since you can know when the user is done, then the only real
solution is to NOT LOAD A NEW copy of word each time.

Further, if there is multiple versions of word running, which one do you
plan to close?

If your code creates the template, prints the template and then closes word
WITHOUT USER intervention, the you can most certainly close down that copy
of word ( in fact, you should).

however, if the user *has* to edit/use the template after you create it,
then you cannot effectively attempt, or try to close down word since you
have no idea when the user is done. So, don't load a new copy of word in
your automation code, but use the existing copy of word that is currently
running in ram.

I have sample word merge system that you can give a try. The code in
virtually ALL places that uses word first tries to find a existing copy of
word that is loaded. Only if word is NOT running is a copy launched.

Check out my word merge example at:

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html
 
Back
Top