Release Winword.exe

V

Vimal

Working on an applications which at the end of a workflow generates
documents using mail merge feature MS Word 2000. If a Word template
has atleast one merge field, then the document generates fine and we
are also able to clear Winword.exe from memory upon calling the Quit
method of the Word Application object. However, if a document does not
have any merge fields, the document generates fine, but Winword.exe is
not released even when the Quit method is called. This instance also
hogs the CPU forcing us to bounce the server frequently.

The following is the gist of the code I have:

Dim objWordDocApp As Object
Dim objWordDOC As Object

Set objWordDocApp = CreateObject("Word.Application")

objWordDocApp.Visible = False
Set objWordDOC = objWordDocApp.Documents.Add(Template:=strFileName,
Visible:=False)

If objWordDOC.MailMerge.fields.Count > 0 Then
'Mailmerge processing goes here
End If

objWordDOC.SaveAs FileName:=strDocToGenPath & strDocToGenName &
".DOC", WritePassword:="password"

If Not objWordDOC Is Nothing Then
Set objWordDOC = Nothing
End If

If Not objWordDocApp Is Nothing Then
objWordDocApp.Quit
Set objWordDocApp = Nothing
End If

I have subsequently solved the problem by changing the Visible
parameter in the Add function from False to True:

Set objWordDOC = objWordDocApp.Documents.Add(Template:=strFileName,
Visible:=True)

However, am not able to understand as to why this should be
happenning. Request any form of explanation to this behaviour so that
we know that this will not lead us to any other problem.

Thanking you in advance.
Vimal
 
M

Malcolm Smith

Do you actually close the objWordDOC object? I see that you orphan the
object but you don't actually close it down but assume that the document
object is destroyed when the application closes.

I would suggest that you close the document object before setting the
pointer to Nothing.

This may have something to do with it.

- Malc
www.dragondrop.com
 

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