E
Ed
Hello All,
One of our clients has reported a problem with mail merge when the merge is
run programmatically. It looks like a Word bug but I wonder if anyone can
advise.
To test, I'm using a document which has a couple of merge fields (Field1,
Field2) and a date field in a header. I'm using Word 2003 but I don't think
the issue is limited to that.
I automate the merge and after the merge, if I move the insertion point past
the section break that the mail merge inserted, and then arrange for the
document to have an extra page (e.g. by Ctrl+Enter), the merge fields in the
second (and subsequent) section's header are "<<Field1>>" and "<<Field2>>"
rather than the proper values. The date field is OK. If I perform the merge
manually (not using code) I don't get the problem.
I'm using the following VBA code in Word for the test:
----------------------------------------------------------------------------------------------
Sub MergeTest()
Const MMMDoc = "C:\temp\TestDoc.doc"
Const DataFile = "C:\temp\TestData.edc"
Dim MergeDoc As Document
Set MergeDoc = Documents.Open(MMMDoc)
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.SuppressBlankLines = True
.OpenDataSource Name:=DataFile, _
Format:=wdOpenFormatText, _
ConfirmConversions:=False, _
ReadOnly:=True, _
LinkToSource:=False
.Execute
End With
End Sub
----------------------------------------------------------------------------------------------
The data file is a tilde-delimited text file.
Thanks.
Ed
One of our clients has reported a problem with mail merge when the merge is
run programmatically. It looks like a Word bug but I wonder if anyone can
advise.
To test, I'm using a document which has a couple of merge fields (Field1,
Field2) and a date field in a header. I'm using Word 2003 but I don't think
the issue is limited to that.
I automate the merge and after the merge, if I move the insertion point past
the section break that the mail merge inserted, and then arrange for the
document to have an extra page (e.g. by Ctrl+Enter), the merge fields in the
second (and subsequent) section's header are "<<Field1>>" and "<<Field2>>"
rather than the proper values. The date field is OK. If I perform the merge
manually (not using code) I don't get the problem.
I'm using the following VBA code in Word for the test:
----------------------------------------------------------------------------------------------
Sub MergeTest()
Const MMMDoc = "C:\temp\TestDoc.doc"
Const DataFile = "C:\temp\TestData.edc"
Dim MergeDoc As Document
Set MergeDoc = Documents.Open(MMMDoc)
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.SuppressBlankLines = True
.OpenDataSource Name:=DataFile, _
Format:=wdOpenFormatText, _
ConfirmConversions:=False, _
ReadOnly:=True, _
LinkToSource:=False
.Execute
End With
End Sub
----------------------------------------------------------------------------------------------
The data file is a tilde-delimited text file.
Thanks.
Ed