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

Get multiple addresses from a contact list



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 30th 09, 02:42 PM posted to microsoft.public.outlook.program_vba
Joel
external usenet poster
 
Posts: 48
Default Get multiple addresses from a contact list

Why doesn't this code work. I only cna get one item from the distribution list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and can't
figure this out.
Ads
  #2  
Old May 30th 09, 04:36 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Get multiple addresses from a contact list

I don't see anything in this code that relates to attaching a distribution
list to a message. Maybe you could clarify what you're trying to do and give
your Outlook version.

Also, no distribution list appears to be involved. Instead, your code
appears to do something with contacts in a particular folder.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel" wrote in message
...
Why doesn't this code work. I only cna get one item from the distribution
list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and can't
figure this out.



  #3  
Old May 30th 09, 04:46 PM posted to microsoft.public.outlook.program_vba
Joel
external usenet poster
 
Posts: 48
Default Get multiple addresses from a contact list

Isn't a ddistribution list all the memberos of a contact list? I trying to
send an email to a list of people at my company that will be the same every
week. What is the best way to get this list into the To: box of the email.
I already have the email and just need to fill in the lisdt of people.

"Sue Mosher [MVP]" wrote:

I don't see anything in this code that relates to attaching a distribution
list to a message. Maybe you could clarify what you're trying to do and give
your Outlook version.

Also, no distribution list appears to be involved. Instead, your code
appears to do something with contacts in a particular folder.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel" wrote in message
...
Why doesn't this code work. I only cna get one item from the distribution
list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and can't
figure this out.




  #4  
Old May 30th 09, 06:13 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Get multiple addresses from a contact list

No, a distribution list is a single Outlook item that contains either
one-off email addresses or pointers to contact items stored in a folder.
What you're talking about is a contacts folder.

You don't need code to work with it, just select all the items in the folder
and use the New Message to Contact command to create a new message to all
those people.

If you do want to write code for such a simple task, use the addresses to
build a string that you use to set the value of the To property on the
message.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel" wrote in message
...
Isn't a ddistribution list all the memberos of a contact list? I trying
to
send an email to a list of people at my company that will be the same
every
week. What is the best way to get this list into the To: box of the
email.
I already have the email and just need to fill in the lisdt of people.

"Sue Mosher [MVP]" wrote:

I don't see anything in this code that relates to attaching a
distribution
list to a message. Maybe you could clarify what you're trying to do and
give
your Outlook version.

Also, no distribution list appears to be involved. Instead, your code
appears to do something with contacts in a particular folder.



"Joel" wrote in message
...
Why doesn't this code work. I only cna get one item from the
distribution
list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and
can't
figure this out.






  #5  
Old May 30th 09, 06:22 PM posted to microsoft.public.outlook.program_vba
Joel
external usenet poster
 
Posts: 48
Default Get multiple addresses from a contact list

I just figured it out myself. I needed code to do what I needed. Can you
directly get an address book by name instead of looping through all the
address boks. Here is what I have now

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName).Items

Set myAddressLists = myNameSpace.AddressLists

For Each itm In myAddressLists
If itm.Name = DistListName Then

For Each mycontact In itm.AddressEntries
If mycontact.DisplayType = olUser Then
If GetDistributionList = "" Then
GetDistributionList = mycontact
Else
GetDistributionList = GetDistributionList & ";" & mycontact
End If
End If

Next mycontact
End If
Next itm




"Sue Mosher [MVP]" wrote:

No, a distribution list is a single Outlook item that contains either
one-off email addresses or pointers to contact items stored in a folder.
What you're talking about is a contacts folder.

You don't need code to work with it, just select all the items in the folder
and use the New Message to Contact command to create a new message to all
those people.

If you do want to write code for such a simple task, use the addresses to
build a string that you use to set the value of the To property on the
message.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel" wrote in message
...
Isn't a ddistribution list all the memberos of a contact list? I trying
to
send an email to a list of people at my company that will be the same
every
week. What is the best way to get this list into the To: box of the
email.
I already have the email and just need to fill in the lisdt of people.

"Sue Mosher [MVP]" wrote:

I don't see anything in this code that relates to attaching a
distribution
list to a message. Maybe you could clarify what you're trying to do and
give
your Outlook version.

Also, no distribution list appears to be involved. Instead, your code
appears to do something with contacts in a particular folder.



"Joel" wrote in message
...
Why doesn't this code work. I only cna get one item from the
distribution
list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and
can't
figure this out.






  #6  
Old May 30th 09, 08:58 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Get multiple addresses from a contact list

Still looking for your Outlook version.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel" wrote in message
...
I just figured it out myself. I needed code to do what I needed. Can you
directly get an address book by name instead of looping through all the
address boks. Here is what I have now

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName).Items

Set myAddressLists = myNameSpace.AddressLists

For Each itm In myAddressLists
If itm.Name = DistListName Then

For Each mycontact In itm.AddressEntries
If mycontact.DisplayType = olUser Then
If GetDistributionList = "" Then
GetDistributionList = mycontact
Else
GetDistributionList = GetDistributionList & ";" &
mycontact
End If
End If

Next mycontact
End If
Next itm




"Sue Mosher [MVP]" wrote:

No, a distribution list is a single Outlook item that contains either
one-off email addresses or pointers to contact items stored in a folder.
What you're talking about is a contacts folder.

You don't need code to work with it, just select all the items in the
folder
and use the New Message to Contact command to create a new message to all
those people.

If you do want to write code for such a simple task, use the addresses to
build a string that you use to set the value of the To property on the
message.

"Joel" wrote in message
...
Isn't a ddistribution list all the memberos of a contact list? I
trying
to
send an email to a list of people at my company that will be the same
every
week. What is the best way to get this list into the To: box of the
email.
I already have the email and just need to fill in the lisdt of people.

"Sue Mosher [MVP]" wrote:

I don't see anything in this code that relates to attaching a
distribution
list to a message. Maybe you could clarify what you're trying to do
and
give
your Outlook version.

Also, no distribution list appears to be involved. Instead, your code
appears to do something with contacts in a particular folder.



"Joel" wrote in message
...
Why doesn't this code work. I only cna get one item from the
distribution
list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and
can't
figure this out.








  #7  
Old May 30th 09, 10:53 PM posted to microsoft.public.outlook.program_vba
Joel
external usenet poster
 
Posts: 48
Default Get multiple addresses from a contact list

need to work with 2003 & 2007

"Sue Mosher [MVP]" wrote:

Still looking for your Outlook version.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Joel" wrote in message
...
I just figured it out myself. I needed code to do what I needed. Can you
directly get an address book by name instead of looping through all the
address boks. Here is what I have now

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName).Items

Set myAddressLists = myNameSpace.AddressLists

For Each itm In myAddressLists
If itm.Name = DistListName Then

For Each mycontact In itm.AddressEntries
If mycontact.DisplayType = olUser Then
If GetDistributionList = "" Then
GetDistributionList = mycontact
Else
GetDistributionList = GetDistributionList & ";" &
mycontact
End If
End If

Next mycontact
End If
Next itm




"Sue Mosher [MVP]" wrote:

No, a distribution list is a single Outlook item that contains either
one-off email addresses or pointers to contact items stored in a folder.
What you're talking about is a contacts folder.

You don't need code to work with it, just select all the items in the
folder
and use the New Message to Contact command to create a new message to all
those people.

If you do want to write code for such a simple task, use the addresses to
build a string that you use to set the value of the To property on the
message.

"Joel" wrote in message
...
Isn't a ddistribution list all the memberos of a contact list? I
trying
to
send an email to a list of people at my company that will be the same
every
week. What is the best way to get this list into the To: box of the
email.
I already have the email and just need to fill in the lisdt of people.

"Sue Mosher [MVP]" wrote:

I don't see anything in this code that relates to attaching a
distribution
list to a message. Maybe you could clarify what you're trying to do
and
give
your Outlook version.

Also, no distribution list appears to be involved. Instead, your code
appears to do something with contacts in a particular folder.


"Joel" wrote in message
...
Why doesn't this code work. I only cna get one item from the
distribution
list

Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myContactList = myFolder.Folders(DistListName)
For Each contact In myContactList.Items

Email = contact.Email1DisplayName
Next contact

I'm trying to attach a distribution list to a new email message and
can't
figure this out.









 




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
Using multiple email addresses from one contact delbert.davis Outlook - Using Contacts 0 February 9th 09 05:16 PM
multiple e-mail addresses merged into distribution list red14red Outlook - Using Contacts 2 October 1st 08 08:17 PM
Multiple email addresses into distribution list nir020 Outlook - Using Contacts 1 November 28th 07 11:44 AM
Displaying multiple e-mail addresses for one contact Tony Reynolds Outlook - Using Contacts 1 February 16th 06 05:15 PM
Contact has multiple email addresses 2nmga Outlook - Using Contacts 2 January 24th 06 02:02 PM


All times are GMT +1. The time now is 02:42 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.