+ Reply to Thread
Results 1 to 12 of 12

Mail-Merge Selected Records to Separate Files

  1. #1
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Mail-Merge Selected Records to Separate Files

    This is a code fragment I wrote to generate separate PDFs for a mail-merge:

    Please Login or Register  to view this content.
    It works GREAT if all the recipients are included (I was so proud!). If they aren't, though, it ratchets through all the selected recipients (good), then has a run-time error on the Exit Do line (bad).

    How do I iterate through just the active records?

    Thank you.
    Last edited by shg; 11-13-2014 at 05:32 PM.
    Entia non sunt multiplicanda sine necessitate

  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: Mail-Merge Selected Records

    I assume you're setting the LastRecord value somewhere, in which case you should be able to use:
    If .ActiveRecord = .LastRecord Then Exit Do
    When you want to process all records, simply set:
    .LastRecord = .RecordCount
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Mail-Merge Selected Records

    Thanks for responding, Paul.

    Ummm ....

    I have random records selected for merge. I don't know how to tell when I've reached the last of the selected records.

  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: Mail-Merge Selected Records

    So how are you selecting the records? Your code seems to want to process all records regardless.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Mail-Merge Selected Records

    From the UI, I select specific records. I want the code to iterate through those selected records.

    Forgive me my naivete, Paul, this is one of the very few times I've tried to automate Word.

    For example,

    Please Login or Register  to view this content.
    Last edited by shg; 11-13-2014 at 01:08 AM.

  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: Mail-Merge Selected Records

    Try:
    Please Login or Register  to view this content.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Mail-Merge Selected Records

    Please Login or Register  to view this content.
    That doesn't work, Paul. There's nothing that binds i to the record being tested for inclusion.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Mail-Merge Selected Records

    Ah:

    Please Login or Register  to view this content.
    Paul, thank you.

  9. #9
    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: Mail-Merge Selected Records

    Hmm, I'm not sure what happened there. In my previous testing, having:
    .ActiveRecord = wdNextDataSourceRecord
    was sufficient. Now it isn't. Using:
    .ActiveRecord = i
    instead seems to work fine.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Mail-Merge Selected Records

    Here's my final code. Thank you again, Paul.

    Please Login or Register  to view this content.
    Last edited by shg; 11-13-2014 at 05:24 PM.

  11. #11
    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: Mail-Merge Selected Records

    You don't need the lines:
    .ViewMailMergeFieldCodes = False
    or:
    .ViewMailMergeFieldCodes = True
    and you've misspelled my name...

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Mail-Merge Selected Records

    I corrected the misspelling a moment ago, sorry.

    I included those lines (and the DoEvents) so I could see the merge field values as it did the merge.

+ 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. Replies: 2
    Last Post: 01-22-2013, 11:37 AM
  2. Replies: 2
    Last Post: 07-12-2012, 08:11 PM
  3. Mail Merge Query - Format of Merge Fields in Word
    By carlosbourn in forum Excel General
    Replies: 2
    Last Post: 11-10-2007, 07:11 AM
  4. Replies: 0
    Last Post: 04-21-2006, 03:40 PM
  5. merge with Word How can I get excel to mail merge zip codes plus 4 correctly?
    By Kathy at Sauder Feeds in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-30-2005, 07:05 AM

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