Consulting

Results 1 to 7 of 7

Thread: vba code in word merge fields

  1. #1
    VBAX Newbie
    Joined
    Oct 2018
    Posts
    4
    Location

    vba code in word merge fields

    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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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-m...-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-m...html#post23345
    http://www.msofficeforums.com/mail-m...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/o...1-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/...f-8642e46fa103
    For some working examples, see:
    http://www.msofficeforums.com/mail-m...-multiple.html
    https://www.excelforum.com/excel-gen...ml#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=5AEDC...43615E886B!566
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Oct 2018
    Posts
    4
    Location
    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.



    Attached Files Attached Files

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    Oct 2018
    Posts
    4
    Location
    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)

  6. #6
    VBAX Newbie
    Joined
    Oct 2018
    Posts
    4
    Location
    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
    Attached Files Attached Files

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The problem is that you've omitted a pair of double quotes:
    "{ MERGEFIELD Course }¶
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •