Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Extracting E-mail adddresses from Outlook (http://www.outlookbanter.com/outlook-vba/7401-extracting-e-mail-adddresses-outlook.html)

robert February 6th 06 04:19 AM

Extracting E-mail adddresses from Outlook
 
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

Michael Bauer February 6th 06 06:47 AM

Extracting E-mail adddresses from Outlook
 
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

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


robert February 6th 06 09:34 PM

Extracting E-mail adddresses from Outlook
 
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

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




All times are GMT +1. The time now is 07:19 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com