A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Extracting E-mail adddresses from Outlook



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 6th 06, 04:19 AM posted to microsoft.public.outlook.program_vba
robert
external usenet poster
 
Posts: 127
Default 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
  #2  
Old February 6th 06, 06:47 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default 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 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

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
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  
Old February 6th 06, 09:34 PM posted to microsoft.public.outlook.program_vba
robert
external usenet poster
 
Posts: 127
Default 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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 06:59 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-2025 Outlook Banter.
The comments are property of their posters.