Link to home
Start Free TrialLog in
Avatar of Sheils
SheilsFlag for Australia

asked on

How to trigger codes to run each time a record mailmerge(MailMergeAfterRecordMerge)

I have some code that normally run on the document close event to register the document into a document management system. It works fine on a single document.

I now want to use it in a mail merge and run it for each record merge. The user will run the mail merge normally from the toolbar.

For each record that merges I want to pull some data from the mail merge data source and use it to register the document before merging the next record.

It seems that the MailMergeAfterRecordMerge is the event that I need to use but I don't quiet understand how to make it trigger.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sheils

ASKER

Hi Rgonzo

Your code works well when merging all records from the recordsource. However it generates an error in line 39 (DocResult.SaveAs "C:\Users\Sheils\Documents\testmerge\" & sFirmPathName & "MailDocument.docx", wdFormatXMLDocument) when you uncheck some of the records in edit recipient list. The error occurs just after the first unchecked record.



Please note that I have added a new line after your line 9 to move the mail wizard to step 6 so that the user don't have to move through the steps each time they use the mail merge.
Avatar of Sheils

ASKER

The code that I have included after your line 9 is

ThisDocument.MailMerge.WizardState = 6
Avatar of Rgonzo1971
Rgonzo1971

Then you will have to go the AfterProduction way

by saving the resulting Doc divided by sections

http://answers.microsoft.com/en-us/office/forum/office_2003-word/use-mail-merge-to-create-multiple-documents/a1f3c40f-36ab-4b4e-ad67-1ee09d7d84a8

Regards
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.