outlook contacts and distribution lists - help???

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()
 
K

Ken Slovak - [MVP - Outlook]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top