Macro to pull members from distribution list.

santhoshbes2729

New Member
Joined
Oct 6, 2016
Messages
15
Hi All,

New to the Excel world. Need your help in providing me the excel macro to pull the member details from outlook distribution list. Can any one help me.

Thank You !!

Regards,
Santy
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The following macro will first create a new worksheet, and then list the details of the specified distribution list in the newly created worksheet. Change the name of the distribution list accordingly. Note that the code needs to be placed in a regular module (Visual Basic Editor >> Insert >> Module).

Code:
Option Explicit

Sub PrintDistListDetails()


    Dim olApplication As Object
    Dim olNamespace As Object
    Dim olContactFolder As Object
    Dim olDistListItem As Object
    Dim destWorksheet As Worksheet
    Dim distListName As String
    Dim memberCount As Long
    Dim memberIndex As Long
    Dim rowIndex As Long
    
    Const olFolderContacts As Long = 10
    
    distListName = "MyDistListName" 'change the name accordingly


    Set olApplication = CreateObject("Outlook.Application")
    Set olNamespace = olApplication.GetNamespace("MAPI")
    Set olContactFolder = olNamespace.GetDefaultFolder(olFolderContacts)
    Set olDistListItem = olContactFolder.Items(distListName)
    
    Set destWorksheet = Worksheets.Add

    destWorksheet.Range("A1:B1").Value = Array("Name", "Address") 'column headers
    
    memberCount = olDistListItem.memberCount
    
    rowIndex = 2 'start the list at Row 2
    For memberIndex = 1 To memberCount
        With olDistListItem.GetMember(memberIndex)
            destWorksheet.Cells(rowIndex, "a").Value = .Name
            destWorksheet.Cells(rowIndex, "b").Value = .Address
        End With
        rowIndex = rowIndex + 1
    Next memberIndex
    
    destWorksheet.Columns.AutoFit
    
    Set olApplication = Nothing
    Set olNamespace = Nothing
    Set olContactFolder = Nothing
    Set olDistListItem = Nothing
    Set destWorksheet = Nothing
    
End Sub

Hope this helps!
 
Last edited:
Upvote 0
Hi Thanks for your reply.

Set olDistListItem = olContactFolder.Items(distListName)

gets a error "An object could not be found"
 
Upvote 0
Did you change the name of the distribution list on this line to the name of your distribution list...

Code:
distListName = "MyDistListName" 'change the name accordingly

???
 
Upvote 0
Is the distribution list located in the default contacts folder?
 
Upvote 0
With the code I offered, the distribution list needs to be within the default contacts folder.
 
Upvote 0
Hi, Thanks for your prompt reply.

I get error "[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]memberCount = olDistListItem.memberCount" for this as "Object does not support this property"

Can you pls help me in resolving this.

thank you !!
[/FONT]
 
Upvote 0
When I tested the code, it ran successfully. I didn't get any errors. Try running it again, but this time when you get the error, click on Debug. This will highlight the line causing the error. Then, while still in debug mode, enter the following line in the Immediate Window (Ctrl+G) and press ENTER...

Code:
? typename(olDistListItem)

Does it return DistListItem?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top