A
Al
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!
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!