outlook contacts and distribution lists - help???

  • Thread starter Thread starter Paul M
  • Start date Start date
P

Paul M

Hi there,

i'm trying to create code that will retrieve the distribution lists in my
contacts folder, and show me the entries in there, but i am having many
problems with it.

i have some similar code that loops through contacts and adds them to a new
distribution list but it is also giving my problems as the
GetDefaultFolder(olFolderContacts).Items is not a collection class.

Any help appreciated.

thanks,
Paul - CODE BELOW.......

Dim myOlApp As New Outlook.Application

Dim myNameSpace As Outlook.NameSpace

Dim myDistList As Outlook.DistListItem

Dim myContact As Outlook.ContactItem

Dim myRecipient As Outlook.Recipient

myNameSpace = myOlApp.GetNamespace("MAPI")

myDistList = myOlApp.CreateItem(Outlook.OlItemType.olDistributionListItem)

myDistList.DLName = InputBox("Enter the name of the new distribution list")

Dim item As Object

For Each item In myNameSpace.GetDefaultFolder(olFolderContacts).Items

If TypeOf item Is ContactItem Then

myContact = item

myRecipient = myNameSpace.CreateRecipient(myContact.FullName)

myRecipient.Resolve()

myDistList.AddMember(myRecipient)

End If

Next

myDistList.Display()
 
You can't use Item like that. Declare an Object variable, since items
in the Items collection can be contacts or DL's.
 
Back
Top