• 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
Post Views: 40

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.

Comments

  1. Benjay says

    July 6, 2018 at 11:37 am

    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.

    Reply
  2. Mark Petereit says

    June 7, 2018 at 3:58 pm

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

    Reply
  3. Alex MacQueen says

    November 22, 2017 at 12:02 pm

    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!

    Reply
    • Diane Poremsky says

      November 22, 2017 at 5:10 pm

      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.

      Reply
      • Alex MacQueen says

        November 23, 2017 at 4:43 am

        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 :)

      • Diane Poremsky says

        November 25, 2017 at 12:53 pm

        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.

  4. Diane Poremsky says

    November 22, 2017 at 7:31 am

    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?

    Reply
  5. Alex MacQueen says

    November 21, 2017 at 7:33 am

    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!

    Reply
    • Diane Poremsky says

      November 21, 2017 at 11:57 am

      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")

      Reply
      • Alex MacQueen says

        November 21, 2017 at 12:12 pm

        Hi Diane - I've used the following:

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

        Thanks!

      • Diane Poremsky says

        November 21, 2017 at 2:34 pm

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

        What does it give you for the path?

      • Alex MacQueen says

        November 22, 2017 at 5:18 am

        Thanks - it says "All Public Folders"

      • Alex MacQueen says

        November 22, 2017 at 5:24 am

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

  6. Matt O\'Connor says

    September 6, 2016 at 4:22 pm

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

    Reply
    • Diane Poremsky says

      September 7, 2016 at 12:32 am

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

      Reply
  7. Martin Reiser says

    April 15, 2016 at 10:20 am

    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

    Reply
    • Diane Poremsky says

      April 16, 2016 at 12:14 am

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

      Reply
  8. Anna says

    November 10, 2015 at 4:20 pm

    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.

    Reply
  9. Alex says

    June 19, 2014 at 10:06 pm

    It worked pretty well on my computer. But on my brother's computer is not working and it says "Run-Time Error (93) Object variable or With block variable not set". Any suggestion?

    Many thanks for your help!

    Alex

    Reply
    • Diane Poremsky says

      June 20, 2014 at 12:18 am

      Did you set the reference to word in the VB Editors Tools, References menu?

      Reply
      • Alex says

        July 1, 2014 at 6:12 am

        Yes, from the beginning, and I've always had that "error (93)"... Thank you for your kind cooperation...

      • Diane Poremsky says

        July 3, 2014 at 12:03 am

        At what point does it fail? Are any lines highlighted in yellow? Is the name entering inter the dialog spelled correctly?

  10. Jennifer says

    April 16, 2014 at 9:46 am

    2010. And yes it was that line that I replaced the code with and where the error comes from.

    Reply
  11. Jennifer says

    April 11, 2014 at 3:24 pm

    I had attempted that before but it gives me a Runtime Error (483) at the Set myFolder line.

    Reply
    • Diane Poremsky says

      April 11, 2014 at 11:38 pm

      That would be this line: Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) ?
      Error 483 means the object doesn't support the action, but I'm not sure why it would be coming up on that line.

      Oh, what version of outlook? Try change the dim line to this: Dim myFolder As Outlook.MAPIFolder

      Reply
  12. Jennifer says

    April 7, 2014 at 4:23 pm

    Hi, I'm working on the same problem with 3 exchange emails configured on my outlook and followed the steps in working with non-default folders to try get it to point to the correct contacts folder to search.

    Doing it that way I wind up with a Run-Time Error (91) beginning at the line: If InStr(1, myDistList.GetMember(y).Name, myListMember)

    Is there something more I need to do to point it to the correct Contacts folder?

    Reply
    • Diane Poremsky says

      April 8, 2014 at 10:06 pm

      I think the runtime error is from something else... but you need to change this, it uses the default folder in the default data file.
      Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)

      try this to use the current folder:
      Set myFolder = myNameSpace.ActiveExplorer.CurrentFolder

      Reply
  13. Andy says

    March 3, 2014 at 7:41 am

    You can also find this information on OWA. Options, See All Options, Groups.

    Reply
  14. Fraser Johnson says

    February 5, 2014 at 11:25 pm

    In Outlook 2003, I get the following issue.

    The line "Dim myFolder As Outlook.Folder" does not compile. Error message is "User-defined type not defined". the Object Browser for Outlook 11.0 has no "Folder" entry, but there is a "Folders" entry. If I correct this line to "Dim myFolder As Outlook.Folders", the code compiles. However, I then get a run-time error '13' at the line "Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)"

    Reply
    • Diane Poremsky says

      February 6, 2014 at 1:15 am

      Hmm. That is old code, it should work in 2003. Try changing the Dim myfolder line to Dim myFolder As Outlook.MAPIFolder - that worked here.

      Reply
  15. Orna says

    September 23, 2013 at 3:56 am

    Thanks Diane
    It works great with 2010 but not in 2007.
    Is there somthing i can do about?

    Reply
    • Diane Poremsky says

      September 23, 2013 at 7:44 am

      It should work in all versions of Outlook, as its a fairly old macro. Did you check macro security settings?

      Reply
  16. Vic Gammill says

    August 8, 2013 at 1:44 pm

    Baby, you fine. And MVP.

    Reply
  17. Alicia says

    July 29, 2013 at 7:04 am

    This is great! Thank you! Is there any way to make it search through the email addresses as opposed to the names?
    Thanks!

    Reply
    • Diane Poremsky says

      July 29, 2013 at 7:14 am

      Change GetMember(y).Name to GetMember(y).Address - it should be used 4 times in the code. (This will find all partial matches - searching for poremsky returns all address containing poremsky.)

      Reply
  18. Mia says

    May 1, 2013 at 1:08 pm

    Hi,

    My outlook is configured to 3 separate email accounts and this macro doesn't seem to want to search the correct address book. Is there a way to specify which contacts folder is searched?

    Reply
    • Diane Poremsky says

      May 1, 2013 at 5:44 pm

      It's set in Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) - this should be your default contacts folder. if the folder is in another data file, see
      Working with VBA and non-default Outlook Folders

      Reply
  19. Mohit says

    January 12, 2013 at 10:10 am

    Hi Diane,

    By any chance is it possible to search the Global address List? what will be the modified code for the same?

    Many thanks for the much needed help!!

    Thanks, Mohit

    Reply
    • Diane Poremsky says

      January 12, 2013 at 8:29 pm

      It might be possible, but you need to use redemption (or CDO) to access the GAL.

      Reply
  20. Stacy says

    January 11, 2013 at 10:14 am

    Thank-you very much!! That worked!

    Reply
  21. Stacy says

    January 10, 2013 at 10:05 am

    Wow this works great, but only seems to search local contacts. How could I modify this to search distribution lists in a Shared Contacts. Basically a secretary needs to be able to search her bosses contacts and modify his Distribution Lists.

    Reply
    • Diane Poremsky says

      January 10, 2013 at 4:12 pm

      This line tells it where to look:
      Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
      Try
      Set myFolder = Application.ActiveExplorer.CurrentFolder

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Latest EMO: Vol. 31 Issue 7

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
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • How to Hide or Delete Outlook's Default Folders
  • This operation has been cancelled due to restrictions
  • Change Outlook's Programmatic Access Options
  • Use Public Folders In new Outlook
  • Removing Suggested Accounts in New Outlook
  • How to Delete Stuck Read Receipts
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
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

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

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

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 © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.