R
Robert
I would like to use the following code as a basis for programmatically
extracting e-mail addresses from my Outlook 2003 to feed to a Pegasus e-mail
client. (I don't like the fact that Outlook displays each recipient's name
in a distribution list.)
The code fails on a “type mismatch†when it reads a Distribution List in my
contacts. I tried looping through ContactItems instead of Contacts, but that
didn’t help. I will readily admit the concept of objects is still a little
fuzzy to me.
Does anyone know a way around this?
Thanks,
Robert
Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim Contact As Object
Dim myOlApp As Outlook.Application
Dim myItem As Outlook.ContactItem
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olContactItem)
' Set the Application object.
Set ol = New Outlook.Application
' Set the Namespace object.
Set olns = ol.GetNamespace("MAPI")
' Set the default Contacts folder.
Set objFolder = olns.GetDefaultFolder(olFolderContacts)
' Set objAllContacts equal to the collection of all contacts.
Set objAllContacts = objFolder.Items
' Loop through each contact.
For Each Contact In objAllContacts
Set myItem = Contact
' Display the Fullname field for the contact.
If myItem.Categories = "Personal" _
And myItem.Email1Address <> "" Then
MsgBox myItem.Email1Address
End If
Next
extracting e-mail addresses from my Outlook 2003 to feed to a Pegasus e-mail
client. (I don't like the fact that Outlook displays each recipient's name
in a distribution list.)
The code fails on a “type mismatch†when it reads a Distribution List in my
contacts. I tried looping through ContactItems instead of Contacts, but that
didn’t help. I will readily admit the concept of objects is still a little
fuzzy to me.
Does anyone know a way around this?
Thanks,
Robert
Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim Contact As Object
Dim myOlApp As Outlook.Application
Dim myItem As Outlook.ContactItem
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olContactItem)
' Set the Application object.
Set ol = New Outlook.Application
' Set the Namespace object.
Set olns = ol.GetNamespace("MAPI")
' Set the default Contacts folder.
Set objFolder = olns.GetDefaultFolder(olFolderContacts)
' Set objAllContacts equal to the collection of all contacts.
Set objAllContacts = objFolder.Items
' Loop through each contact.
For Each Contact In objAllContacts
Set myItem = Contact
' Display the Fullname field for the contact.
If myItem.Categories = "Personal" _
And myItem.Email1Address <> "" Then
MsgBox myItem.Email1Address
End If
Next