S
Stephen Barrett
I have a strange performance issue when iterating through a MailMerge Fields
collection. I have 2 documents that I am peforming mail merge with. I am
doing this on a server (I know it isn't technically supported) and
everything works great and has been for some time.
These 2 new documents were taking over 3 minutes to mail merge with a tab
delimited datasource file. I tracked it down to a routine we built that
verifies that the datasource has all the fields that the mailmerge document
is expecting to avoid nasty hidden dialog boxes on the server. The routine
works great and is almost always extremely quick.
If I merge either of the 2 documents individually within an instance of a
Document through automation via VB.Net, everything works great and is fast.
However, if I try both (merge 1st, close doc, open 2 doc, merge 2nd), the
routine slows down severely. I have commented a bunch of code out to where
it was only iterating the MailMerge.Fields collection and it still happens.
These 2 documents happen to be larger (500k +) documents. Whats strange is
that I can do either of these individually or combined with 20 other
documents and it works.
Watching task manager, it the Word process goes to 0% and stays that way for
like 3 minutes in the situation.
Has anyone seen this type of problem before?
Below is a snippet of the code that performs the validation. Note: it still
has issues even if I comment out all the Regex and other internal method
calls.
TIA for any help,
Stephen
Dim ocMergeFields As Object = oDoc.MailMerge.Fields
nCount = ocMergeFields.Count
For Each oMergeField As Object In ocMergeFields
If oMergeField.Type = 59 Then
Dim mc As MatchCollection = r.Matches(oMergeField.Code.Text)
For Each m As Match In mc
' We actually want to get group 1 which is the result of the
match
If (m.Groups.Count > 1) Then
Dim sField As String =
GetComparableMergeFieldName(m.Groups(1).Value)
If (Not alFields.Contains(sField)) Then
alFields.Add(sField)
End If
End If
Next
End If
Next
collection. I have 2 documents that I am peforming mail merge with. I am
doing this on a server (I know it isn't technically supported) and
everything works great and has been for some time.
These 2 new documents were taking over 3 minutes to mail merge with a tab
delimited datasource file. I tracked it down to a routine we built that
verifies that the datasource has all the fields that the mailmerge document
is expecting to avoid nasty hidden dialog boxes on the server. The routine
works great and is almost always extremely quick.
If I merge either of the 2 documents individually within an instance of a
Document through automation via VB.Net, everything works great and is fast.
However, if I try both (merge 1st, close doc, open 2 doc, merge 2nd), the
routine slows down severely. I have commented a bunch of code out to where
it was only iterating the MailMerge.Fields collection and it still happens.
These 2 documents happen to be larger (500k +) documents. Whats strange is
that I can do either of these individually or combined with 20 other
documents and it works.
Watching task manager, it the Word process goes to 0% and stays that way for
like 3 minutes in the situation.
Has anyone seen this type of problem before?
Below is a snippet of the code that performs the validation. Note: it still
has issues even if I comment out all the Regex and other internal method
calls.
TIA for any help,
Stephen
Dim ocMergeFields As Object = oDoc.MailMerge.Fields
nCount = ocMergeFields.Count
For Each oMergeField As Object In ocMergeFields
If oMergeField.Type = 59 Then
Dim mc As MatchCollection = r.Matches(oMergeField.Code.Text)
For Each m As Match In mc
' We actually want to get group 1 which is the result of the
match
If (m.Groups.Count > 1) Then
Dim sField As String =
GetComparableMergeFieldName(m.Groups(1).Value)
If (Not alFields.Contains(sField)) Then
alFields.Add(sField)
End If
End If
Next
End If
Next