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

Re: Automating Mail Merge in Word by Doug

Doug
Tue Oct 31 13:01:13 CST 2006

Are you sure that "1 Project Engagement Description.doc" is a mail merge
main document with a datasource attached to it?

You may need to include:

.MainDocumentType = wdFormLetters
.OpenDataSource "Drive:\Path\Filename"


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"RalphK" <RalphK@discussions.microsoft.com> wrote in message
news:3EFFF10F-E47E-4B33-BE20-ACF24D70A45E@microsoft.com...
>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



Re: Automating Mail Merge in Word by Willms

Willms
Tue Oct 31 13:40:17 CST 2006

Am Tue, 31 Oct 2006 17:14:02 UTC, schrieb RalphK
<RalphK@discussions.microsoft.com> auf
microsoft.public.word.vba.general :

> With ActiveDocument.MailMerge
> .Destination = wdSendToNewDocument

> When I play back the macro, it chokes on the following line:
>
> .Destination = wdSendToNewDocument
>
> with runtime error 5852. Requested object is not available.

With your document, check out the following:

------------------

Private Function give_Mailmerge_Status_Text(mmStatus As Long) As
String
Select Case mmStatus
Case wdNormalDocument ' 0
gib_Mailmerge_Status_Text = "normal Dokument"
Case wdMainDocumentOnly ' 1
gib_Mailmerge_Status_Text = "Main dokument w/out Daten Source"
Case wdMainAndDataSource ' 2
gib_Mailmerge_Status_Text = "Main dokument with Data source"
Case wdMainAndHeader ' 3
gib_Mailmerge_Status_Text = "Main dokument with Header"
Case wdMainAndSourceAndHeader ' 4
gib_Mailmerge_Status_Text = "Main dokument with Datasource und
Header"
Case wdDataSource ' 5
gib_Mailmerge_Status_Text = "Data source"
Case Else
gib_Mailmerge_Status_Text = "unknown MailMerge-Status"
End Select
End Function

Public Sub zeigen_Mailmerge_Status()

Call MsgBox("MailMerge Status is: " & ActiveDocument.MailMerge.State
& " = " _
& give_Mailmerge_Status_Text(ActiveDocument.MailMerge.State),
vbOKOnly, ActiveDocument.Name)
End Sub

What do you see?


Yours,

Re: Automating Mail Merge in Word by RalphK

RalphK
Tue Oct 31 14:13:01 CST 2006

The message is:

MailMerge Status is: 0 = normal Dokument.

RalphK

"Lüko Willms" wrote:

> Am Tue, 31 Oct 2006 17:14:02 UTC, schrieb RalphK
> <RalphK@discussions.microsoft.com> auf
> microsoft.public.word.vba.general :
>
> > With ActiveDocument.MailMerge
> > .Destination = wdSendToNewDocument
>
> > When I play back the macro, it chokes on the following line:
> >
> > .Destination = wdSendToNewDocument
> >
> > with runtime error 5852. Requested object is not available.
>
> With your document, check out the following:
>
> ------------------
>
> Private Function give_Mailmerge_Status_Text(mmStatus As Long) As
> String
> Select Case mmStatus
> Case wdNormalDocument ' 0
> gib_Mailmerge_Status_Text = "normal Dokument"
> Case wdMainDocumentOnly ' 1
> gib_Mailmerge_Status_Text = "Main dokument w/out Daten Source"
> Case wdMainAndDataSource ' 2
> gib_Mailmerge_Status_Text = "Main dokument with Data source"
> Case wdMainAndHeader ' 3
> gib_Mailmerge_Status_Text = "Main dokument with Header"
> Case wdMainAndSourceAndHeader ' 4
> gib_Mailmerge_Status_Text = "Main dokument with Datasource und
> Header"
> Case wdDataSource ' 5
> gib_Mailmerge_Status_Text = "Data source"
> Case Else
> gib_Mailmerge_Status_Text = "unknown MailMerge-Status"
> End Select
> End Function
>
> Public Sub zeigen_Mailmerge_Status()
>
> Call MsgBox("MailMerge Status is: " & ActiveDocument.MailMerge.State
> & " = " _
> & give_Mailmerge_Status_Text(ActiveDocument.MailMerge.State),
> vbOKOnly, ActiveDocument.Name)
> End Sub
>
> What do you see?
>
>
> Yours,
>

Re: Automating Mail Merge in Word by Doug

Doug
Tue Oct 31 15:32:38 CST 2006

As I suspected, "1 Project Engagement Description.doc" is not a mail merge
main document and as a result, it does not have a data source attached to it
and that is the reason why your attempt to execute the merge fails.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"RalphK" <RalphK@discussions.microsoft.com> wrote in message
news:B2EF8C23-BB21-4606-BEF1-92A4FEE4369B@microsoft.com...
> The message is:
>
> MailMerge Status is: 0 = normal Dokument.
>
> RalphK
>
> "Lüko Willms" wrote:
>
>> Am Tue, 31 Oct 2006 17:14:02 UTC, schrieb RalphK
>> <RalphK@discussions.microsoft.com> auf
>> microsoft.public.word.vba.general :
>>
>> > With ActiveDocument.MailMerge
>> > .Destination = wdSendToNewDocument
>>
>> > When I play back the macro, it chokes on the following line:
>> >
>> > .Destination = wdSendToNewDocument
>> >
>> > with runtime error 5852. Requested object is not available.
>>
>> With your document, check out the following:
>>
>> ------------------
>>
>> Private Function give_Mailmerge_Status_Text(mmStatus As Long) As
>> String
>> Select Case mmStatus
>> Case wdNormalDocument ' 0
>> gib_Mailmerge_Status_Text = "normal Dokument"
>> Case wdMainDocumentOnly ' 1
>> gib_Mailmerge_Status_Text = "Main dokument w/out Daten Source"
>> Case wdMainAndDataSource ' 2
>> gib_Mailmerge_Status_Text = "Main dokument with Data source"
>> Case wdMainAndHeader ' 3
>> gib_Mailmerge_Status_Text = "Main dokument with Header"
>> Case wdMainAndSourceAndHeader ' 4
>> gib_Mailmerge_Status_Text = "Main dokument with Datasource und
>> Header"
>> Case wdDataSource ' 5
>> gib_Mailmerge_Status_Text = "Data source"
>> Case Else
>> gib_Mailmerge_Status_Text = "unknown MailMerge-Status"
>> End Select
>> End Function
>>
>> Public Sub zeigen_Mailmerge_Status()
>>
>> Call MsgBox("MailMerge Status is: " & ActiveDocument.MailMerge.State
>> & " = " _
>> & give_Mailmerge_Status_Text(ActiveDocument.MailMerge.State),
>> vbOKOnly, ActiveDocument.Name)
>> End Sub
>>
>> What do you see?
>>
>>
>> Yours,
>>