Managing WINWORD processes

I

Igor

Hello,

I have an application that opens up Word documents however when the user
closes Word outside the application, the WINWORD process still runs. Any tips
on managing this so we don't end up with 10 Word processes and slow the PC to
a grinding halt?

Maybe there is a way to dispose of the Word._Application object as soon as
the user closes Word but how would this be triggered? I am creating a new
Word._Application object for every document the user open; I have tried to
enclose it in a using statement but it doesn't seem to work.

Thanks,
Igor
 
P

Pesach Shelnitz

Hi Igor,

Code that needs to use an instance of the WINWORD process from another
application, can first check if an instance of WINWORD exists before opening
a new instance.

The following Excel macro switches to Word, but creates a new instance of
WINWORD only if no instance of WINWORD exists.

Sub GoToWord()

Const wdWindowStateMaximize = 1

Dim wordApp As Object

On Error Resume Next
Set wordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wordApp = CreateObject("Word.Application")
MsgBox "A new instance of Word was created."
Else
MsgBox "An open instance of Word will be used."
End If
On Error GoTo 0
With wordApp
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
End With
Set wordApp = Nothing
End Sub

If you use similar code, it shouldn't matter whether or the user closes the
WINWORD process outside of your application.
 
C

Cindy M.

Hi Igor,
Maybe there is a way to dispose of the Word._Application object as soon as
the user closes Word but how would this be triggered?

How about monitoring the application's Quit or DocumentClose event(s)?

Another possibility would be to monitor the application window's existance
via the Windows API.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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