Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

How to automate MailMerge and suppress error and other messages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Al - 21 Mar 2008 20:25 GMT
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!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.