VBA script to allow mail merges of distribution groups?

Status
Not open for further replies.

mr_malkovich

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Hey all. Is there a code that will allow me to mail merge distribution groups? So for instance if I mail merged 20 distribution groups, I'd end up with 20 emails in my outbox, and each would be going to the email addresses assigned to their groups?

Thanks as always..
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
i don't have any code that does that but i have code that will mail merge to members of a DL - one address per message.

http://www.slipstick.com/developer/mail-merge-members-contact-group/ has normal mail merge behavior of individual messages but uses the members of a contact group (dl) as the source.

Outlook can resolve the group names, so I'd make a text list of the group names and use it as the address source. You need to make sure the names are unique so outlook doesn't resolve them to the wrong person or group.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Well, my initial thought when you first asked was no, but upon further reflection, I think so. I think you'd want to use an outlook form, not a traditional mail merge in word, and copy it using VBA as you send it to each group. Deciding how to pick up the group names would be the hardest part - do you select them in contacts and run the macro, add them to the message you are using as the merge message then break the recipients list up for each message, pick from a list...
 

mr_malkovich

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I like to think I'm good with Outlook, but I understood about 3% of that. When you say use an Outlook form, do you mean a contact form?
Could some kind of app be designed to make this a smooth process? Every day I email a couple of hundred people using mail merge. Some of them need to receive the email individually, and others need to receive it along with a couple other members of their organization. Currently I stop them all in the outbox and go in and manually delete all but one of the emails that are headed to individual members of one company, then manually add their email addresses to the To section of the remaining email then send them all off when I've gone through the whole outbox. Painful.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sorry about that, I meant outlook mail message. Create the message, add all DLs to the To field then run the macro to copy the message and send it to each group individually.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
To use, create a message, enter the Contact groups (or contacts) in the To field then run the macro. Close the original message. put it in thisoutlooksession and add a button to the qat.

http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/

Code:
Sub MailMergeDL() 
Dim objApp As Outlook.Application 
Dim objItem As Outlook.MailItem 
Dim objMsg As Outlook.MailItem 
Dim objOutlookRecip As Recipient 
Dim Recipients As Recipients 
 
Dim i As Integer 
 
Set objApp = Application 
Set objItem = objApp.ActiveInspector.CurrentItem 
 
If objItem.Recipients.Count > 0 Then
  For i = 1 To objItem.Recipients.Count 
  
   Set objMsg = objApp.CreateItem(olMailItem) 
  
   With objMsg 
     .HTMLBody = objItem.HTMLBody 
     .Subject = objItem.Subject 
     .Recipients.Add objItem.Recipients(i) 
    End With 
  
   For Each objOutlookRecip In objMsg.Recipients 
        objOutlookRecip.Resolve 
    Next 
  
   objMsg.Display ' use Send to send automatically
   Next i 
 
End If 
' close the merge message without saving 
objItem.Close olDiscard 'use olSave to save it as a draft 
 
Set objItem = Nothing 
Set objApp = Nothing 
 
End Sub
 

mr_malkovich

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Wow. Interesting. Going to carve some time to get to grips with this and get back to you. Thanks as always, Diane.
 
Status
Not open for further replies.
Top