• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Send a mailmerge email - code in vb to take info from a spreadsheet

I have a data source file (excel) and a template. I tried to do a mailmerge, but my problem lies in the fact that I need to send multiple lines of data to the same agent. (when agent name is the same). Please see the two files attached and maybe you can give me some direction on how to do this.

so for example:
If agent name is Amy X
Display all lines in the mailmerge where agent name is Amy X. This may be 1 line or 10 lines

thanks in advance Email.docx
1 Solution
This is a one-to-many situation.

Mail merge is not designed to do that, but there are several workaround methods. Which is best depends on the details of the data and your skill level. If you need further help with any of the methods, let us know.

There are a couple of techniques that do not use VBA.

If you have a limited number of subsidiary items, you can arrange your datasource so that each item has its own field.

Forename, Surname, address1, address2, postcode, item1, item2, item3, item4,... itemN.

Another is to use Word Fields IF and MERGESEQ

Here are four approaches that use VBA.

This one uses VBA (in Access, but it could be in Word)  to create an individual document per customer.

This talks about hooking into the  MailMergeAfterRecordMerge event to create a recordset for each customer's orders.

Here VBA is used to split a single-table merge output into individual tables.

This one is a Directory type merge to a Word table. The datasource is a flat file or the result of a one-to-many query. The merge fields are set up in the Word table to receive the 'many' data.

The MailMergeBeforeRecordMerge event is used to look for a change of data in the One table. It then starts a new document Section, saves the data from the one side fields using Word VBA techniques, and carries on until the next change.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now