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

Find the Distribution Lists a Contact Belongs to

Slipstick Systems

› Outlook › People › Find the Distribution Lists a Contact Belongs to

Last reviewed on September 13, 2017     42 Comments

Applies to: Outlook (classic), Outlook 2007, Outlook 2010

Also works with Outlook's Contact Groups (which are distribution lists with a friendlier name).

Run the macro, enter a contact's name in the Input box then press OK to create a list of the DLs the contact belongs to in a Word document. Use the exact name to return only that contact, or a partial name to return all contacts with similar names.
Search for names

Leave the field blank and press OK to create a list of the members of all DLs.

A sample of the output when getting a list of all DLs and members (the name field is left blank). Click the image to see the full version with multiple DLs listed.:
Sample Results after using the Macro

This works in all versions of Outlook.

To search by email address, use GetMember(y).Address instead of GetMember(y).Name. (It's used 4 times in the code.) This will find all partial matches, for example, searching for 'poremsky' will find all addresses containing my last name anywhere in the email address.)

VBA Code sample

A text file of this macro is here.

Copy and paste this code into Outlook's VBA editor and set the references to Word.

    ' Code sample written by Graham Mayor -  Word MVP 
    ' //www.gmayor.com 

Sub ListNames()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder 'use Outlook.MAPIFolder if Outlook.folder fails. 
Dim myDistList As Outlook.DistListItem
Dim myFolderItems As Outlook.Items
Dim myListMember As String
Dim sList As String
Dim x As Integer
Dim y As Integer
Dim iCount As Integer

myListMember = InputBox("Enter name of list member to be found")
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myFolderItems = myFolder.Items
  iCount = myFolderItems.Count
   sList = ""
  For x = 1 To iCount
    If TypeName(myFolderItems.Item(x)) = "DistListItem" Then
  Set myDistList = myFolderItems.Item(x)
  For y = 1 To myDistList.MemberCount
      If InStr(1, myDistList.GetMember(y).Name, myListMember) Then
        'MsgBox myDistList.GetMember(y).Name & vbInformation, "Distribution List"
      If sList = "" Then
        sList = sList & myDistList.GetMember(y).Name & vbTab & myDistList.DLName
      Else
        sList = sList & vbCr & myDistList.GetMember(y).Name & vbTab & myDistList.DLName
      End If
      End If
    Next y
    End If
  Next x
    
   On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err Then
      Set wdApp = CreateObject("Word.Application")
    End If

   Set wdDoc = wdApp.Documents.Add
     wdApp.Visible = True
     wdApp.Activate
   With wdDoc.Range
    .InsertAfter sList
    .ParagraphFormat.TabStops.ClearAll
    .ParagraphFormat.TabStops.Add Position:=InchesToPoints(4), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
   End With

Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

Set References

You need to go to Tools, References (in the VBA Editor) and add Word as a reference.

In this screenshot, it lists Word 14. If you use an older version of Word, you'll have a different version here.

Set the VB references

Find the Distribution Lists a Contact Belongs to was last modified: September 13th, 2017 by Diane Poremsky

Related Posts:

  • How to convert contact groups to individual contacts using Import or a
    Create Individual Contacts from a Distribution List
  • How to share distribution list (contact groups) with other users, or w
    Sharing Distribution Lists
  • Outlook and Exchange Distribution Lists
  • Add a Category to Contacts in a Contact Group

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
42 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Benjay (@guest_211464)
July 6, 2018 11:37 am
#211464

This code seems to run but only displays an empty Word doc. I am running this script at work on a work computer. Thank you in advance.

0
0
Reply
Mark Petereit (@guest_211247)
June 7, 2018 3:58 pm
#211247

Sweet! I was just about to start writing something like this.

0
0
Reply
Alex MacQueen (@guest_209445)
November 22, 2017 12:02 pm
#209445

No worries :)

It's Exchange 2010 SP3 I believe.

The path looks to be correct, other than for the folder "Research / Sales" it shows in the Msgbox as "Research %2F Sales", would this be likely to cause a problem or should it still work for that specific path?

Thanks!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Alex MacQueen
November 22, 2017 5:10 pm
#209446

That could be the problem. It's a "url escape code" and the path you are passing is looking for the /. Try using that format and see if it works.

0
0
Reply
Alex MacQueen (@guest_209457)
Reply to  Diane Poremsky
November 23, 2017 4:43 am
#209457

OK it doesn't look like it's that - if I change the path to use the escape code it fails there with an "object not found" error. Switch it back to the "/" character and it goes straight past there until it fails at the "For y = 1 To myDistList.MemberCount" line again. On the plus side it does therefore seem to be locating the correct folder from the path at least!
Could there be anything that might prevent the macro from accessing the distributions/contact groups within the final folder? My AD account has full read/write access to those contact groups so I would hope not - what is that line attempting to do if you'll excuse my ignorance?

Really appreciate your help so far - many thanks :)

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Alex MacQueen
November 25, 2017 12:53 pm
#209474

Thanks for the update. Yeah, if it’s getting to there, it’s failing on the dl. If you can open the dl and look at it, you should be able to get the count using a macro.

What it’s trying to do is count the number of contacts in the dl. Does the dl contain nested dls? That shouldn’t cause errors in counting since you are counting members, not contacts specifically. I’ll see if I can reproduce it but might not have a chance before Tuesday.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
November 22, 2017 7:31 am
#209444

I didn't think that thru.... Sorry. Use your original path and msgbox myfolder.folderpath - I'm thinking the path isn't right and this will show if your path is correct.

Oh, what version of exchange do you use?

0
0
Reply
Alex MacQueen (@guest_209421)
November 21, 2017 7:33 am
#209421

Hi - I managed to get this working for my own contacts folder, but when I change the myFolder variable to point to the public folders the macro fails at this point:

For y = 1 To myDistList.MemberCount

It's not a particularly helpful error message either:

Run-time error '-1040171003 (c2004005) The operation failed

Any help much appreciated!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Alex MacQueen
November 21, 2017 11:57 am
#209423

what code are you using to reference the public folder? The mail folder is olPublicFoldersAllPublicFolders so you'd need to walk down it
set folder = Ns.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("top level").folders("company contacts")

0
0
Reply
Alex MacQueen (@guest_209425)
Reply to  Diane Poremsky
November 21, 2017 12:12 pm
#209425

Hi Diane - I've used the following:

Set myFolder = myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Organisation (BeGo)").Folders("Research / Sales").Folders("Distribution Lists")

Thanks!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Alex MacQueen
November 21, 2017 2:34 pm
#209430

try Set myFolder = myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders)
msgbox myfolder

What does it give you for the path?

0
0
Reply
Alex MacQueen (@guest_209440)
Reply to  Diane Poremsky
November 22, 2017 5:18 am
#209440

Thanks - it says "All Public Folders"

0
0
Reply
Alex MacQueen (@guest_209441)
Reply to  Diane Poremsky
November 22, 2017 5:24 am
#209441

And if I then use my original path, it gives "Distribution Lists", which seems to be correct?

0
0
Reply
Matt O\'Connor (@guest_201373)
September 6, 2016 4:22 pm
#201373

I tried using this but the word document that is created is empty. Any ideas as to what is going wrong?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Matt O\'Connor
September 7, 2016 12:32 am
#201378

Any error messages? comment out any on error resume next lines to see if it errors.

0
0
Reply
Martin Reiser (@guest_197889)
April 15, 2016 10:20 am
#197889

The line of code "If TypeName(myFolderItems.Item(x)) = "DistListItem" Then always responds negative, therefore no items are created for the list.

Any ideas?

Thanks for your help.

Martin

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Martin Reiser
April 16, 2016 12:14 am
#197925

That line is looking for DLs and should only return negative if there are no dl's (contact groups).

0
0
Reply
Anna (@guest_194685)
November 10, 2015 4:20 pm
#194685

This is fantastic ... I have been dreaming of this ... With that being said, we use a shared contact list that we add through public folders. As I am not a programmer by trade I am not sure which part of the code I should be changing so that it references the specific shared contacts folder and not my personal contacts. Any help/direction that you can provide would be great. Thank you.

1
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
  • How to Hide or Delete Outlook's Default Folders
  • This operation has been cancelled due to restrictions
  • Remove a password from an Outlook *.pst File
  • Outlook SecureTemp Files Folder
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Count and List Folders in Classic Outlook
  • 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
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

Count and List Folders in Classic Outlook

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

Newest Code Samples

Count and List Folders in Classic Outlook

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

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