Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Thread Tools Display Modes
Old 12-17-2019, 11:48 AM
hhorber hhorber is offline Edit mailmerge recipient list using a macro Windows 10 Edit mailmerge recipient list using a macro Office 2016
Edit mailmerge recipient list using a macro
Join Date: Apr 2018
Posts: 2
hhorber is on a distinguished road
Default Edit mailmerge recipient list using a macro

In Word 2016 unfortunately it is not possible to record the procedure <Edit Recipient List> within a mail merge document to print selected recipients only.

The VBA code below can be used to fullfill this task:

Module 1

Sub Test_EditRecipientList()

   ' Edit Recipient List using a VBA macro and print selected recipients

   Dim ch1 As String
   Dim ch2 As String
   Dim ch3 As String
   Dim TableName As String
   Dim TableField As String
   Dim FilterCriteria As String

   ' The following 3 variables may be adapted according to your Excel Worksheet
   ch1 = "TABLE_1"         ' Name of the Table within the EXCEL Worksheet
   ch2 = "CATEGORY"        ' Name of the Field within the referenced table which is to be filtered
   ch3 = "STWEG_Hansmatt"  ' The recipients which meat this criteria are selected and printed
   ' Do not change the following 3 lines
   TableName = "`" & ch1 & "`"
   TableField = "`" & ch2 & "`"
   FilterCriteria = "'" & ch3 & "'"
   Call EditRecipientList(TableName, TableField, FilterCriteria)
End Sub
Module 2

Sub EditRecipientList(TableName As String, TableField As String, FilterCriteria As String)

    Dim strQry_Current As String
    strQry_Current = ActiveDocument.MailMerge.DataSource.QueryString  ''Info fü Debug
    With ActiveDocument.MailMerge
       .DataSource.QueryString = "SELECT * FROM " & TableName
    End With
    With ActiveDocument.MailMerge
       .DataSource.QueryString = "SELECT * FROM " & TableName & "  WHERE " & TableField & " = " & FilterCriteria
       .Destination = wdSendToNewDocument
       .SuppressBlankLines = True
           With .DataSource
              .FirstRecord = wdDefaultFirstRecord
              .LastRecord = wdDefaultLastRecord
           End With
       .Execute Pause:=False
    End With

End Sub

Last edited by hhorber; 12-18-2019 at 02:22 AM.
Reply With Quote

edit recipient list, print selected recipients, word vba mail merge

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit mailmerge recipient list using a macro Macro to insert an image to a word mailmerge document based on the value of a mailmerge field? Jake93 Word VBA 3 07-02-2019 05:38 PM
Edit mailmerge recipient list using a macro Mail Merge using edit recipient list option not working properly Dsr122076 Mail Merge 1 12-03-2015 04:19 PM
Edit mailmerge recipient list using a macro Edit mail merge recipient list Freddies_grandad Mail Merge 7 12-10-2012 11:05 PM
Edit mailmerge recipient list using a macro How to edit recipient list rsmedley Mail Merge 1 03-17-2012 01:35 AM
Problem with Edit Recipient List TanMan Word 0 10-05-2011 12:34 PM

All times are GMT -7. The time now is 03:01 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd. is not affiliated with Microsoft