• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Common Problems
    • Outlook BCM
    • Utilities & Addins
    • Video Tutorials
    • EMO Archives
    • Outlook Updates
    • Outlook Apps
    • Outlook & iCloud Issues
    • Forums

Mail merge and Send from a Distribution Group

Slipstick Systems

› Outlook › Mail merge and Send from a Distribution Group

Last reviewed on March 15, 2018   —  9 Comments

August 22, 2014 by Diane Poremsky 9 Comments

Can you use a distribution group as sender when sending mail merge using Microsoft Word and Outlook?

No, you can't send the merge from other addresses using Word's mail merge function. You cannot use a distribution group when you send a mail merge because mail merges use the default email address in Outlook. If the address belonged to a shared mailbox, you can send a mail merge from a shared mailbox address by creating a profile for the shared mailbox.

When you use this Outlook macro to complete the mail merge, you will be able to send from other email addresses, including a distribution group address in Exchange Global Address List or a shared mailbox. As a bonus, you can add attachments to the messages as you merge.

Merge to email

To use: Create a document and insert merge fields; the content of the document is used in the merged email message. Save the document (Outlook uses the filename as the message subject) but leave the document open on the screen. Switch to Outlook, select the contacts you're sending the merge to then run the macro.

This code looks for merge fields for the first, last, and company names but you can add more fields if you need them.

For testing purposes, the macro displays the merged messages on the screen. To send the messages automatically, change .Display to .Send.

Public Sub MailMergeAttachments()    
    Dim currentExplorer As Explorer
    Dim Selection As Selection
    Dim oContact As ContactItem
    Dim oMail As MailItem
    
    Dim attach As Attachment
    Dim obj As Object
    Dim filename As String
    Dim imagePath As String
    Dim oWord As Word.Application
    Dim tmp As String
    ' Uses current user's profile
    Dim enviro As String
    enviro = CStr(Environ("USERPROFILE"))
    On Error Resume Next

    Set oWord = GetObject(, "Word.Application")

' document is open on screen
 oWord.Documents(1).Activate
 
    Set currentExplorer = Application.ActiveExplorer
    Set Selection = currentExplorer.Selection
 
  If Not TypeOf Selection.Item(1) Is Outlook.ContactItem Then
  MsgBox "You need to select Contacts first!"
  Exit Sub
  End If
  
For Each obj In Selection

'Test for ContactGroups
 If TypeName(obj) = "ContactItem" Then
 Set oContact = obj
 
Dim mText As String
Dim f As Word.Field

For Each f In oWord.Documents(1).Fields

  If f.Type = wdFieldMergeField Then
      
 ' match Word mergefields with Outlook fields
      Select Case f.Code
       Case " MERGEFIELD First "
       mText = oContact.FirstName
       
       Case " MERGEFIELD Last "
       mText = oContact.LastName
       
       Case " MERGEFIELD Company "
       mText = oContact.CompanyName
                
       End Select
       
     f.Result.Text = mText
 End If

Next
 
Set oMail = Application.CreateItem(olMailItem)

With oMail
    .To = oContact.Email1Address
  ' trims .docx off a file name to use as subject
    .Subject = Left(oWord.Documents(1).Name, Len(oWord.Documents(1).Name) - 5)
  ' The content of the document is used as the body for the email
    .Body = oWord.Documents(1).Content
    .Attachments.Add enviro & "\Dropbox\file.txt"
    .SentOnBehalfOfName = "sales@domain.com"
  ' use display for testing, change to .send to send automatically. 
    .Display ' .send
End With
 
 End If
    Next
    Set oWord = Nothing
    Set currentExplorer = Nothing
    Set obj = Nothing
    Set Selection = Nothing

End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Mail merge and Send from a Distribution Group was last modified: March 15th, 2018 by Diane Poremsky
  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Share on Skype (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to print (Opens in new window)

Related Posts:

  • Mail Merge to Email using an Outlook Macro
  • Print Outlook Business Card Images
  • Print Contacts and Contact Photos
  • How to replicate Outlook's New letter to Contact feature using a custo
    Create a Letter to a Contact using VBA

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Leave a Reply

9 Comments on "Mail merge and Send from a Distribution Group"

2500
Photo and Image Files
 
 
 
Audio and Video Files
 
 
 
Other File Types
 
 
 
2500
Photo and Image Files
 
 
 
Audio and Video Files
 
 
 
Other File Types
 
 
 

  Subscribe  
newest oldest most voted
Notify of
user
user
Share On TwitterShare On Google

Thanks for the code, however it keeps popping out with error that I need to select the contact first. Is there a extra that needs to be done?

Vote Up00Vote Down Reply
March 15, 2018 11:05 pm
Diane Poremsky
Diane Poremsky
Share On TwitterShare On Google

Hmmm. That title doesn't seem right. :) Oh, it's to do merge of selected contacts and send it From a DL. If you want to use a DL/contact group in a merge, i have a macro around here somewhere that does that too.

You'll need to select the contacts - the code sample checks the item type:
If Not TypeOf Selection.Item(1) Is Outlook.ContactItem Then
MsgBox "You need to select Contacts first!"
Exit Sub
End If

Vote Up00Vote Down Reply
March 15, 2018 11:55 pm
Diane Poremsky
Diane Poremsky
Share On TwitterShare On Google

if you want to send a merge to the members of a contact group, see

Mail Merge to Contact Groups

Vote Up00Vote Down Reply
March 15, 2018 11:59 pm
Marty
Marty
Share On TwitterShare On Google

I really like how this works, however, i need to send an HTML email and all that this spits out is text. I can't really tell why, so I was wondering if this is the intended behavior. Thanks!

Vote Up00Vote Down Reply
December 28, 2017 3:50 pm
Diane Poremsky
Diane Poremsky
Share On TwitterShare On Google

it should use the default mail format - if not, you can force it to use HTML.

in the with omail block, add this before the .body line.
.BodyFormat = olFormatHTML
you may need to change .Body to .htmlbody.

Vote Up00Vote Down Reply
December 28, 2017 11:08 pm
Marty
Marty
Share On TwitterShare On Google

That *did* set it to HTML in the message, but, unfortunately, still none of the formatting from the word document is showing up in the email.

Vote Up00Vote Down Reply
December 29, 2017 11:40 am
Diane Poremsky
Diane Poremsky
Share On TwitterShare On Google

looks like you'll need to copy and paste instead - https://www.slipstick.com/developer/code-samples/paste-formatted-text-vba/ shows how to do it. It's also possible to apply formatting to the text after its added to the message - this works best if you either need everything formatted the same or want to format a specific phrase or line.

Vote Up00Vote Down Reply
December 30, 2017 9:47 pm
John
John
Share On TwitterShare On Google

Thanks for the article. I am getting a compile error on this line (Method or data member not found).

Set currentExplorer = Application.ActiveExplorer

I understand 'ActiveExplorer' is not a property of Application, but I don't know how to resolve it?

Vote Up1-1Vote Down Reply
October 5, 2017 12:03 pm
Diane Poremsky
Diane Poremsky
Share On TwitterShare On Google

Are you using this macro in Outlook or Word? It's an Outlook macro.

Vote Up2-2Vote Down Reply
October 5, 2017 2:01 pm

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 23 Issue 10

Subscribe to Exchange Messaging Outlook






Our Sponsors

  • Popular
  • Latest
  • Week Month All
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Remove the Primary Account from Outlook
  • Pictures Don't Display in Outlook Messages
  • To Cc or Bcc a Meeting Request
  • Outlook is Not Recognized as the Default Email Client
  • Remove a password from an Outlook *.pst File
  • Understanding Outlook's Auto-Complete Cache (*.NK2)
  • Exchange Account Set-up Missing in Outlook 2016
  • The Signature or Stationery and Fonts button doesn't work
  • Security Certificate Warning in Microsoft Outlook
  • iCloud error: Outlook isn't configured to have a default profile
  • Setting Custom Reminder Times
  • Add Additional Addresses to Room Mailboxes
  • Create a Task from a Message and include the Attachment
  • Forward email messages by date
  • Open multiple Outlook windows when Outlook starts
  • Office 365 Fraud Detection Checks
  • Outlook Request: Calendar Details View
  • Outlook's "Not Junk" option isn't available
Ajax spinner

Newest VBA Samples

Open multiple Outlook windows when Outlook starts

Set most frequently used Appointment Time Zones

How to change the From field on incoming messages

VBA: File messages by client code

Update Contact Area Codes

Set a reminder on selected items in the To-Do List

Replicate GTD: Create a task after sending a message

Use VBA to read fields in attached messages

Move Outlook Folders using VBA

Replicate Smart Lookup using a macro

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Better Outlook Reminders?
  • Coming Soon to Windows 10: Office 365 Search
  • Outlook Links Won’t Open In Windows 10
  • BCM Errors after Upgrading to Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook 2016 Top Issues

  • The Windows Store Outlook App
  • Emails are not shown in the People Pane (Fixed)
  • Calendars aren’t printing in color
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • BCM Errors after October 2017 Outlook Update
  • Excel Files Won’t Display in Reading Pane
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

OutlookCode.com

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes
  • “Live” Group Calendar Tools

Convert to / from Outlook

  • Converting Messages and Calendar or
    Address books
  • Moving Outlook to a New Computer
  • Moving Outlook 2010 to a new Windows computer
  • Moving from Outlook Express to Outlook

Recover Deleted Items

  • Recover deleted messages from .pst files
  • Are Deleted Items gone forever in Outlook?

Outlook 2013 Absolute Beginner's Guide

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Sync & Share

Share Calendar & Contacts

Synchronize two machines

Sharing Calendar and Contacts over the Internet

More Tools and Utilities for Sharing Outlook Data

Access Folders in Other Users Mailboxes

View Shared Subfolders in an Exchange Mailbox

"Live" Group Calendar Tools

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Outlook BCM | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2018 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

You are going to send email to

Move Comment