Solved

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

Posted on 2011-09-27
1
261 Views
Last Modified: 2012-05-12
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
List.xlsx
0
Comment
Question by:damixa
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 36713291
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.
e.g.

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

Another is to use Word Fields IF and MERGESEQ
http://support.microsoft.com/kb/294686/

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.
http://www.experts-exchange.com/Applications/MS_Office/Word/Q_21090605.html

This talks about hooking into the  MailMergeAfterRecordMerge event to create a recordset for each customer's orders.
http://www.experts-exchange.com/Applications/MS_Office/Word/Q_21478463.html

Here VBA is used to split a single-table merge output into individual tables.
http://www.experts-exchange.com/Applications/MS_Office/Word/Q_21633674.html

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.
http://www.experts-exchange.com/Applications/MS_Office/Word/Q_21669663.html
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now