R
RalphK
I am trying to automate a mail merge in Word. I am using Office 2003. My
source document is a Microsoft Excel file. My target document is a Word mail
merge document. I have done the steps manually and recorded the following
macro:
Option Explicit
Sub Fennessey1()
'
' Fennessey1 Macro
' Macro recorded 10/31/2006 by Ralph K
'
Documents.Open FileName:="""1 Project Engagement Description.doc""", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
ActiveDocument.SaveAs FileName:="Test1.doc",
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword _
:="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False
End Sub
When I play back the macro, it chokes on the following line:
.Destination = wdSendToNewDocument
with runtime error 5852. Requested object is not available.
Can anyone tell me what is wrong.
RalphK
source document is a Microsoft Excel file. My target document is a Word mail
merge document. I have done the steps manually and recorded the following
macro:
Option Explicit
Sub Fennessey1()
'
' Fennessey1 Macro
' Macro recorded 10/31/2006 by Ralph K
'
Documents.Open FileName:="""1 Project Engagement Description.doc""", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
ActiveDocument.SaveAs FileName:="Test1.doc",
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword _
:="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False
End Sub
When I play back the macro, it chokes on the following line:
.Destination = wdSendToNewDocument
with runtime error 5852. Requested object is not available.
Can anyone tell me what is wrong.
RalphK