I am trying to do some automation on distribution lists, but am running into a snag. In a distribution list the GetMember method returns a Recipient object which has a limited amount of information and I want to get the Contact object represented by the Recipient. I test to make sure the recipient is resolved, but when I attempt to use the AddressEntry.GetContact method I get a run time error. What am I doing wrong or what else do I need to do?
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myFolderItems = myFolder.Items
iCount = myFolderItems.Count
For x = 1 To iCount
If TypeName(myFolderItems.Item(x)) = "DistListItem" Then
Set myDistList = myFolderItems.Item(x)
For y = 1 To myDistList.MemberCount
Set myRecipient = myDistList.GetMember(y)
RecipientIsResolved = myRecipient.Resolved
If RecipientIsResolved = True Then
Set myAddressEntry = myRecipient.AddressEntry
Set myContactItem = myAddressEntry.GetContact '<Errors here with "The item could not be found"
With myContactItem
'Here I would be able to access all of the contact's information
End With
End If
Debug.Print myDistList.GetMember(y).Name
' If myDistList.GetMember(y).Name = myNameSpace.CurrentUser.Name Then
' MsgBox "Your are a member of " & myDistList.DLName
' End If
Next y
End If
Next x
Thanks!
David
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myFolderItems = myFolder.Items
iCount = myFolderItems.Count
For x = 1 To iCount
If TypeName(myFolderItems.Item(x)) = "DistListItem" Then
Set myDistList = myFolderItems.Item(x)
For y = 1 To myDistList.MemberCount
Set myRecipient = myDistList.GetMember(y)
RecipientIsResolved = myRecipient.Resolved
If RecipientIsResolved = True Then
Set myAddressEntry = myRecipient.AddressEntry
Set myContactItem = myAddressEntry.GetContact '<Errors here with "The item could not be found"
With myContactItem
'Here I would be able to access all of the contact's information
End With
End If
Debug.Print myDistList.GetMember(y).Name
' If myDistList.GetMember(y).Name = myNameSpace.CurrentUser.Name Then
' MsgBox "Your are a member of " & myDistList.DLName
' End If
Next y
End If
Next x
Thanks!
David