![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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 |
#2
|
|||
|
|||
![]()
Am Sun, 5 Feb 2006 20:19:28 -0800 schrieb Robert:
After the For Each line you need to check the objects type. Because myItem is declared as ContactItem the line will fail on DistListItems. This works: If TypeOf Contact is Outlook.ContactItem Then Set myItem=Contact ... Endif BTW: If you send the mail to yourself and set the DL into the BCC field then no recipient will see any other name. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- 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 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 didnt 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 |
#3
|
|||
|
|||
![]()
Thank you - that did work.
Your suggestion for using the BCC field is a good one. It would save me the trouble of having to extract the names and addresses. Cheers, Robert "Michael Bauer" wrote: Am Sun, 5 Feb 2006 20:19:28 -0800 schrieb Robert: After the For Each line you need to check the object´s type. Because myItem is declared as ContactItem the line will fail on DistListItems. This works: If TypeOf Contact is Outlook.ContactItem Then Set myItem=Contact ... Endif BTW: If you send the mail to yourself and set the DL into the BCC field then no recipient will see any other name. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- 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 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Extracting music from e-mail message | Connie Martin | Outlook Express | 11 | February 22nd 06 02:03 PM |
Extracting sound files from Outlook 2002 emails | [email protected] | Outlook - General Queries | 2 | February 18th 06 05:01 AM |
extracting email messages out of Journal | Martin Rhodes | Outlook - General Queries | 0 | January 30th 06 11:05 PM |