• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Add Email Addresses to a Contact Group

Slipstick Systems

› Developer › Code Samples › Add Email Addresses to a Contact Group

Last reviewed on April 20, 2017     2 Comments

I'd like to quickly - with a click or two, assign a particular sender of email to a Contact Group.

You can use a macro to add the sender of a selected message to a Contact Group (aka distribution list or DL) in one click (ok, two, as you need to select the Contract group name too).

When you run this macro after selected an email message, it asks if you want to add to an existing contact group or create a new one.

message box asking what you want to do

If you choose to add it to an existing list, a list box containing the names of your existing Contact Groups displays. Double click on a name to add the email address to that list. If you said you wanted to create a new Contact Group, you'll enter a name for the Contact Group in the InputBox that comes up.

Run the userform

  1. To use this project, right click on Project1 and choose Insert > Userform.
  2. Select Listbox from the Toolbox and add it to the userform and drag to resize. Add a Command button.
    toolbox dialog
  3. Change the form and button captions in Properties.
    userform properties
  4. Right click on the userform and choose View code.
  5. Paste the first macro in the code page.
  6. The completed userform will resemble this:
    create a simple userform with a list box
  7. Right click on Project1 and choose Insert > Module.
  8. Paste the second macro in the new module.
  9. Select a message and run the macro to test it

Userform Code

Private Sub UserForm_Initialize()
Debug.Print "UF", myGroups
With ListBox1
    .Clear
    .List = Split(myGroups, ",")
End With
lbl_Exit:
  Exit Sub
End Sub
 
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
For lngCount = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lngCount) = True Then
        strDLName = ListBox1.List(DLCount)
    End If
    Next
    Unload Me
  
lbl_Exit:
  Exit Sub
End Sub

Private Sub CommandButton1_Click()
For lngCount = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lngCount) = True Then
        strDLName = ListBox1.List(lngCount)
    End If
    Next
     
    Unload Me
  
lbl_Exit:
  Exit Sub
End Sub

Module Code

Paste this macro in a new module.

    Public strDLName As String
    Public myGroups As String

Public Sub AddToDLGroup()
    Dim oDLGroup As Outlook.DistListItem
    Dim oRecipients As Outlook.Recipients
    Dim oMail As MailItem
    Dim newMail As MailItem
    Dim contactItems As Object
     
    Dim ContactsFolder As Outlook.Folder
    Dim Result As Integer
    Dim iCount As Integer
    myGroups = ""
    DLCount = 0
    
    
    On Error Resume Next
    Set oMail = Application.ActiveExplorer.Selection.Item(1)
    If TypeName(oMail) <> "MailItem" Then
       MsgBox "You need to select an email message."
       Exit Sub
    End If

    Set ContactsFolder = Application.Session.GetDefaultFolder(olFolderContacts)
        
    Result = MsgBox("Add to an existing Contact Group or create a new Contact Group?" & _
          vbCrLf & "Click Yes to select an existing Contact Group" & _
          vbCrLf & "No to create a New group ", _
          vbQuestion + vbYesNoCancel, "Contact Group already exists")
        
        If Result = vbYes Then
        
          Set contactItems = ContactsFolder.Items
            iCount = contactItems.Count
            If iCount = 0 Then
            MsgBox "No Contact Groups exist yet"
            Exit Sub
            End If
                For x = 1 To iCount
                If TypeName(contactItems.Item(x)) = "DistListItem" Then
                    myGroups = contactItems.Item(x) & "," & myGroups
                Debug.Print myGroups
                End If
                Next x
                
            UserForm1.Show

Set objContactItems = ContactsFolder.Items.Restrict("[FullName] = '" & strDLName & "'")
    
    If objContactItems.Count > 0 Then
        For Each objItem In objContactItems
                If objItem.Class = Outlook.olDistributionList Then
                Set oDLGroup = objItem
                Exit For
            End If
        Next
    End If

        ElseIf Result = vbNo Then
          strDLName = InputBox("Specify a name for your New Contact Group:", "Contact Group Name")
            Set oDLGroup = Application.CreateItem(olDistributionListItem)
            oDLGroup.DLName = strDLName
        Else
            Exit Sub
        End If
        

    Set newMail = oMail.Reply
    Set oRecipients = newMail.Recipients
            With oDLGroup
                .AddMembers oRecipients
' just save and close
                '.Close olSave
' if you want to see that the address was added to the DL
                .Save
                .Display
            End With
    
    newMail.Close olDiscard
    
    Set oMail = Nothing
    Set oRecipients = Nothing
    Set oDLGroup = Nothing
        
End Sub

More Information

If you don't want to create the form yourself (it's really, really easy), I have a form and module ready for import. Download and unzip AddtoGroup code then right click on Project1 and choose Import. Select UserForm1.frm then repeat with the with AddtoGroup.bas.

Add Email Addresses to a Contact Group was last modified: April 20th, 2017 by Diane Poremsky

Related Posts:

  • Apply Filtered Views Using a Macro
  • Mail merge to members of a contact group
  • Create a list of Contact Group members and their phone numbers
  • How to convert contact groups to individual contacts using Import or a
    Create Individual Contacts from a Distribution List

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.

Subscribe
Notify of
2 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Boris (@guest_205793)
April 8, 2017 8:15 am
#205793

How to create distribution lists from contacts of a certain category?
For example, in the Contacts folder there is a group of 100 contacts belonging to the category "Green".
After running the macro in the address book there are 5 distribution lists from 20 contacts in each of them.
The names of distribution lists can look like this: "Green-1", "Green-2", etc.

"Create a Contact Group from selected Contacts" https://www.howto-outlook.com/howto/addcontactstodl.htm - is no automation in it. Selecting elements manually, manually specifying the name, there is no category selection. I'm interested in the automatic processing of an array of elements in a category - enumeration of elements, creating and filling groups, naming them by mask.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Boris
April 9, 2017 4:59 pm
#205809

You need to get a list of categories - https://www.slipstick.com/developer/get-color-categories-and-restore-them-using-vba/ - then filter by each category, create the list and move on to the next category. if you need to split each category into multiple lists, you'll need to add a counter and create a new group every 20.

Unless you need to do this often, it would be easier to group by category, select some contacts and create the groups. Especially if you are not skilled with vba - as it could take you hours to write (and test) a macro to do it.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 15

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • Remove a password from an Outlook *.pst File
  • Reset the New Outlook Profile
  • Maximum number of Exchange accounts in an Outlook profile
  • Save Attachments to the Hard Drive
  • How to Hide or Delete Outlook's Default Folders
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
  • Use PowerShell to Delete Attachments
  • Remove RE:, FWD:, and Other Prefixes from Subject Line
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Newest Code Samples

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

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

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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

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

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment