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