Obtaining Distribution List Names using CDO

  • Thread starter Thread starter Henry Stockbridge
  • Start date Start date
H

Henry Stockbridge

Hi,

I am attempting to obtain the names and e-mail addresses from members
of a Distribution List, but my code produces Error: 424 'Object
Required.' (See code below at === Error here ===> line.)

I am using Windows XP, Outlook 2003 and have set a reference to
Microsoft CDO 1.21 Library.

Any help you can lend would be appreciated.

- Henry

====================================================

Public Sub GetDistListInfo()

Dim cdosession As MAPI.Session
Dim cdoAddressLists As MAPI.AddressLists
Dim cdoAddresslist As MAPI.AddressList
Dim cdoaddressentries As MAPI.AddressEntries
Dim cdoaddressentry As MAPI.AddressEntry
Dim DistList As String
DistList = "DistributionListNameHere"
Set cdosession = New MAPI.Session

cdosession.Logon

Set cdoAddressLists = cdosession.AddressLists
Set cdoAddresslist = cdoAddressLists.Item("Global Address List")
Set cdoaddressentries = cdoAddresslist.AddressEntries
Set cdoaddressentry = cdoaddressentries.Item(DistList)

=== Error here ===> For Each cdoaddressentry In
cdoaddressentry.Members
Debug.Print cdoaddressentry.Name & ">" & _
Trim(Mid(cdoaddressentry.Address, _
(InStr(1, cdoaddressentry.Address, "Recipients/cn=") + 14), 100))
_
& ">" & DistList
Next
cdosession.Logoff
Set cdosession = Nothing
Set cdoAddressLists = Nothing
Set cdoAddresslist = Nothing
Set cdoaddressentries = Nothing
Set cdoaddressentry = Nothing

End Sub

=========================================
 
Hi Henry,
Set cdoaddressentry = cdoaddressentries.Item(DistList)

Probably this doesn´t return the expected AddressEntry, that´s why
cdoaddressentry.members is nothing.
 
If DistList is the name enclose it in quotes. If not you would need to use
the name or iterate the AddressEntries collection to see which individual
AddressEntry objects are indeed GAL DL's and not recipients.

The MAPI property PR_OBJECT_TYPE (0x0FFE0003) should = 8 (MAPI_DISTLIST) for
any DL's in the GAL.
 
Back
Top