PDA

View Full Version : Outlook Distribution



ry94080
04-19-2018, 11:28 AM
Hi all,

Is there a way to pull the members of an Outlook global distribution list via Access VBA?

SamT
04-21-2018, 10:09 AM
Moderator Bump

PhilS
04-21-2018, 12:08 PM
Is there a way to pull the members of an Outlook global distribution list via Access VBA?

Yes, sure. Here is some code to retrieve the members from all distribution lists in your default contacts folder.


Public Sub PrintContactLists()

Dim app As Outlook.Application
Dim distListItems As Outlook.Items
Dim distList As Outlook.DistListItem
Dim members As String
Dim i As Long

Set app = New Outlook.Application

Set distListItems = app.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items.Restrict("[MessageClass]='IPM.DistList'")
For Each distList In distListItems
Debug.Print "Name: " & distList.DLName
Debug.Print "Number of Members: " & distList.MemberCount
For i = 1 To distList.MemberCount
members = members & distList.GetMember(i).Name & ", "
Next
Debug.Print "Members:" & members
members = ""
Next distList

Set distList = Nothing
Set distListItems = Nothing

End Sub