Word Automation

Joined
Feb 13, 2008
Messages
3
Reaction score
0
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
 
Last edited:
Joined
Feb 13, 2008
Messages
3
Reaction score
0
Automation Fix

I resolved the problem, at least for now.

After "Set MyMerge = MergeDoc.MailMerge"
I added

With MyMerge
.MainDocumentType = wdFormLetters
.OpenDataSource _
Name:="D:\Shares\Data\Collections\WordData.accdb", _
LinkToSource:=True, ReadOnly:=True, AddToRecentFiles:=False, _
Connection:="TABLE tblLegalFormMerge"
End With

I don't know if this is the best solution but it worked.
 

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