Group: microsoft.public.word.vba.general
From: "Doug Robbins - Word MVP"
Date: Saturday, March 22, 2008 5:12 PM
Subject: Re: How to automate MailMerge and suppress error and other messages

You can probably use

Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndDataSource Then myMerge.Execute

That comes from the Visual Basic Help File when F1 is pushed when the
selection is after the work MailMerge in the VBE.

--
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

"Al" wrote in message
news:FD3A30D9-9679-483B-B5A3-2B823B167D1A@microsoft.com...
>I have an process I am developing which will read all the document names in
>a
> folder, process them one-by-one doing a mail merge with the same Excel
> spreadsheet, saving the merged document to a set folder, close the
> document
> and process the next document. Some folders have 80 to 700 documents.
>
> If I run into errors I really don't care as the next process will pick
> that
> up, I just want to open a document, merge, save as another document. How
> can
> I do this, currently I get errors that ask me to connect to the Excel
> spreadsheet, and when a merge field on a document doesn't exist in the
> spreadsheet it stops and wants me to do something with it.
>
> Below is the code I am using in the PrintDocument Function:
>
> strSaveName = "C:\ADOCS\" & strSaveName
>
> 'Open, Merge, Save New Document, and Close the template file
> appWord.Documents.Open (strDoc)
> With appWord.ActiveDocument.MailMerge
> .SuppressBlankLines = True
> .OpenDataSource Name:=Application.CurrentProject.Path &
> "\MergeData.xls", LinkToSource:=True, SQLStatement:="SELECT * FROM
> `tblMergeData`"
> .Destination = wdSendToNewDocument
> .Execute
> End With
> appWord.ActiveDocument.Fields.Update
> appWord.ActiveDocument.SaveAs strSaveName
> appWord.ActiveDocument.Close savechanges:=0
>
> Exit_Here:
> Exit Function
>
> =======================================
> Thanks for your assistance!
>
>