I'm upgrading a 2000 database to 2007. In the current database I perform letter merges thru automation. I can not get them to work in 2007. Although I've created a new mail merge document and provided a data source when I attempt to perform the merge it gives me a message that the document is not a Mail Merge Main Document. I've using the following code. If anyone can help I would be grateful.
Sub WordMerge(varDocument As String, varLetter)
Dim WordDoc As Word.Application
Dim MergeDoc As Word.Document
Dim MyMerge As Word.MailMerge
Set WordDoc = New Word.Application
WordDoc.Documents.Open varDocument ' Document Name and Path
Set MergeDoc = WordDoc.Application.Documents(varLetter) 'Document Name
Set MyMerge = MergeDoc.MailMerge
If MyMerge.State = wdMainAndDataSource Then
MyMerge.Execute
End If
MergeDoc.Close wdDoNotSaveChanges
WordDoc.Visible = True
End Sub
Sub WordMerge(varDocument As String, varLetter)
Dim WordDoc As Word.Application
Dim MergeDoc As Word.Document
Dim MyMerge As Word.MailMerge
Set WordDoc = New Word.Application
WordDoc.Documents.Open varDocument ' Document Name and Path
Set MergeDoc = WordDoc.Application.Documents(varLetter) 'Document Name
Set MyMerge = MergeDoc.MailMerge
If MyMerge.State = wdMainAndDataSource Then
MyMerge.Execute
End If
MergeDoc.Close wdDoNotSaveChanges
WordDoc.Visible = True
End Sub
Last edited: