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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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 = "HCL-Brightstar-MIM" '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
 
Upvote 0
The fact that it returned ContactItem means that "HCL-Brightstar-MIM" refers to a regular contact, not the name of your distribution list. Maybe the name of your distribution list is incorrect? Or, maybe you think you've created a distribution list, but you've actually created a contact?
 
Upvote 0
Is the distribution list located in the default contacts folder?
In my case, the distribution list resides in a global list (At least I think that's where it is. But it's not in my personal default contact list).

What changes do I need to make to read from a different folder? And how would I find out the name of the folder it is in?

Thank you.

Dennis
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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