+ Reply to Thread
Results 1 to 9 of 9

Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

  1. #1
    Registered User
    Join Date
    05-28-2017
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    13

    Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    I have a mail merge document which gets it's source data from an Access Database query.
    Sometimes in Word, I'll edit the Recipient List, and deselect some of the records.
    Is there a way in VBA, to know which recipients are selected, and which are unselected?

    The purpose is because I have a piece of code which will loop through the records and export each as a PDF with a unique name.
    But this currently loops through ALL recipients/records, including the unselected ones.

    Thanks!

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    When you apply filters, that modifies the mailmerge query string, which can be tested via VBA. For example:
    Please Login or Register  to view this content.
    However, done correctly, you shouldn't need to test that. For example, the macro in 'Send Mailmerge Output to Individual Files' at http://www.msofficeforums.com/mail-m...ps-tricks.html will only output the filtered records.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    05-28-2017
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    13

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    Hi Paul,
    Thanks for the link - some really good tips in there, i'll use that on another project.
    I've checked out the query string, it's not helping me
    Here is a screen shot of the Edit Recipients dialog, i'd like to be able to read which of these are ticked/unticked in VBA.

    Capture.PNG

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    The QueryString would work if you'd filtered by 'FirstName', for example, returning something like:
    SELECT * FROM `DATA$` WHERE `FirstName` = 'Mike'
    I'm not sure how to go about retrieving the list of records filtered on the 'Data Source' list, though.

  5. #5
    Registered User
    Join Date
    05-28-2017
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    13

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    Yeah I think from what I've found via Google, it might not be possible.
    Was hoping a guru on here might have proved me wrong.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    Did you try the 'Send Mailmerge Output to Individual Files' code in the link I posted?

  7. #7
    Registered User
    Join Date
    05-28-2017
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    13

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    I didn't... but now that I've tried it, it may actually work.

    Except .MailMerge.DataSource.RecordCount is returning -1
    If I manually change this to the number of records ticked, it's ok.

    In my code I've been advancing the records using .ActiveRecord = wdNextRecord, until the .ActiveRecord doesn't increase by this statement. Then I know I've completed the Export for all records.

    Thoughts?

    My connection setup looks like this:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    OK, try it this variation on the code in the link:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-28-2017
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    13

    Re: Word Mail Merge - VBA to know that recipients are unselected in 'Edit Recipient List'

    Thanks...
    Setting .ActiveRecord to 0 doesn't work, it ignores this instruction and goes to 1. so then your .activerecord=wdnextrecord was skipping the first record.
    Also i'm not sure that .FirstRecord and .LastRecord can be set to wdNextRecord?
    So I needed to tweak your code a bit, but I have got something working now!

    I was trying to step through the records and export the host document as a PDF.
    Your method is Executing the merge, to create a new document, and exporting that new document as a PDF. And it works!

    Here is our combined code

    Please Login or Register  to view this content.
    Needs a bit of a tidy up, but working for now.
    Thanks heaps!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mail merge with CC and BCC recipients
    By emina002 in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2016, 04:11 PM
  2. Replies: 3
    Last Post: 01-18-2016, 12:04 AM
  3. Mail merge - edit recipients list using macro
    By PAUL41EXCEL in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2015, 09:52 AM
  4. Replies: 0
    Last Post: 01-05-2015, 07:35 AM
  5. Word 2007 Mail Merge allows to send one message to multi recipients
    By wowow in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2011, 08:22 AM
  6. [SOLVED] Can't edit or Refresh under mail merge recipients
    By Jennifer Mcdermeit in forum Excel General
    Replies: 1
    Last Post: 07-25-2006, 09:05 AM
  7. [SOLVED] Word's Mail Merge of an Excel List
    By Jack Gillis in forum Excel General
    Replies: 6
    Last Post: 06-11-2006, 02:50 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1