PDA

View Full Version : vba code in word merge fields



tommy77
05-20-2019, 11:59 PM
Hi,

I have an Excel list of people who are interested in more than one course. For every course they are interested in, there's a row with name, address, course name...

f.e Person x is interested in courses 1, 2 and 3. (so there are 3 rows for person x)
Person y is interested in courses 2 and 4 . (so there are 2 rows for person y)

Now I want to send letters to person x and y, using merge fields in Word. Is there a possibility to get the following result in the letter:

Dear person x,

You are interested in following the following courses: <<merged field, summarizing the 3 courses mentioned before>>


AND

Dear person y,


You are interested in following the following courses: <<merged field, summarizing the 2 courses mentioned before
>>


etc.
Anyone an idea on how to do that? The goal is not to print 3 letters for person x, but only one containing the 3 courses.

Thanks!
Tommy

macropod
05-21-2019, 12:53 AM
You can use Word's Catalogue/Directory Mailmerge facility for this (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my Microsoft Word Catalogue/Directory Mailmerge Tutorial at:
http://www.msofficeforums.com/mail-merge/38721-microsoft-word-catalogue-directory-mailmerge-tutorial.html
or:
http://www.gmayor.com/Zips/Catalogue%20Mailmerge.zip
The tutorial covers everything from list creation to the insertion & calculation of values in multi-record tables in letters. Do read the tutorial before trying to use the mailmerge document included with it.

Depending on what you're trying to achieve, the field coding for this can be complex. However, since the tutorial document includes working field codes for all of its examples, most of the hard work has already been done for you - you should be able to do little more than copy/paste the relevant field codes into your own mailmerge main document, substitute/insert your own field names and adjust the formatting to get the results you desire. For some worked examples, see the attachments to the posts at:
http://www.msofficeforums.com/mail-merge/9180-mail-merge-duplicate-names-but-different-dollar.html#post23345
http://www.msofficeforums.com/mail-merge/11436-access-word-creating-list-multiple-records.html#post30327

Another option would be to use a DATABASE field in a normal ‘letter’ mailmerge main document and a macro to drive the process. An outline of this approach can be found at: http://answers.microsoft.com/en-us/office/forum/office_2010-word/many-to-one-email-merge-using-tables/8bce1798-fbe8-41f9-a121-1996c14dca5d
Conversely, if you're using a relational database or, Excel workbook with a separate table with just a single instance of each of the grouping criteria, a DATABASE field in a normal ‘letter’ mailmerge main document could be used without the need for a macro. An outline of this approach can be found at:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_winother-mso_2010/mail-merge-to-a-word-table-on-a-single-page/4edb4654-27e0-47d2-bd5f-8642e46fa103
For some working examples, see:
http://www.msofficeforums.com/mail-merge/37844-mail-merge-using-one-excel-file-multiple.html
https://www.excelforum.com/excel-general/1273421-merge-excel-list-into-word-receipt.html#post5110813

Alternatively, you may want to try one of the Many-to-One Mail Merge add-ins, from:
Graham Mayor at http://www.gmayor.com/ManyToOne.htm; or
Doug Robbins at https://onedrive.live.com/?cid=5AEDCB43615E886B&id=5AEDCB43615E886B!566

tommy77
05-21-2019, 02:10 AM
Thanks Paul!

Want to look into that but I'm having problems accessing the attachments in your links. I've registered myself on msofficeforums but don't receive an email for the account confirmation (also not in my spam folder), so in the meantime I can't open the attachments to have a look at them.



I attached an example list and letter to illustrate my question.

macropod
05-21-2019, 03:04 AM
I just had a look on msofficeforums and you appear to be online there... besides which, the second link I posted doesn't require a user account for access.

tommy77
05-21-2019, 03:47 AM
That’s right Paul, tried again to receive the mail confirmation and now it works. I was able to log in before, not to open the attachment. Looking into it and hope I’ll get it working! There’s a promising example in one of the links (the one about the donations)

tommy77
05-21-2019, 06:52 AM
Hello Paul,

Been trying to adapt one of the attachments from the links you provided in your previous post. I've been able to link it to the Excel sheet I provided before, but I'm struggling with a few things I can't figure out (I'm completely new to this matter):

- The courses are listed next to each other and I want them each on a separate line.
- There's a footer of the original example I can't get away :-)
- The original example makes the text after the courses appear on each letter, but I only get it on the first letter...

Can you please tell me what I'm doing wrong?

Thanks in advance!
Tommy

macropod
05-21-2019, 03:39 PM
The problem is that you've omitted a pair of double quotes:
"{ MERGEFIELD Course }¶