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!
Doug Robbins - Word MVP - 22 Mar 2008 23:12 GMT
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.

Signature
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
>I have an process I am developing which will read all the document names in
>a
[quoted text clipped - 34 lines]
> =======================================
> Thanks for your assistance!