Welcome to the fracta.net forum!

Share your coding ideas or ask questions.

Question Outlook VBA get names of all members of a Group in Excel

More
12 years 4 months ago #50 by roller
Let's say you have a list of Outlook email group names in an Excel file in column A and you want to list all the indivudual members of this Outlook group in column B. You can use the sample code below to achieve this.

From an Excel file open the VBA editor and add a reference to the Outlook libraray from the tools menu and create a new module and copy the code below:

Sub distList()
Dim app As Outlook.Application
Set app = New Outlook.Application
Set objNamespace = app.GetNamespace("MAPI")

Dim re As Outlook.Recipient
Dim dl As Outlook.ExchangeDistributionList

For e = 2 To 10 ' or what ever is the last row in your Excel file mine is 10 and row 1 was a header

Set re = objNamespace.CreateRecipient(Cells(e, 1))
If re.Resolve() Then
Set dl = re.AddressEntry.GetExchangeDistributionList
If Not dl Is Nothing Then
For i = 1 To dl.Members.Count
Cells(e, 2) = dl.Members(i).Name & "; " & Cells(e, 2)
Next
End If
End If
Next e

End Sub

Running this macro will read the group name from Coloumn A from rows 2 to 10 and list all the members in Column B. The group name spelling must match that in Outlook.

Please Log in or Create an account to join the conversation.

Time to create page: 0.870 seconds
Powered by Kunena Forum