Get multiple addresses from a contact list

Status
Not open for further replies.
S

Sm9lbA

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.
 
S

Sue Mosher [MVP]

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

"Joel" <Joel> wrote in message

news:A04725E8-A78F-4257-B072-FBAFE2A4B689@microsoft.com...
> 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.
 
S

Sm9lbA

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

> "Joel" <Joel> wrote in message
> news:A04725E8-A78F-4257-B072-FBAFE2A4B689@microsoft.com...
> > 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.


>
 
S

Sue Mosher [MVP]

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

"Joel" <Joel> wrote in message

news:359F429E-9876-4772-821A-063E185277B0@microsoft.com...
> 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" <Joel> wrote in message
> > news:A04725E8-A78F-4257-B072-FBAFE2A4B689@microsoft.com...
> > > 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.

>

>
>>
 
S

Sm9lbA

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

> "Joel" <Joel> wrote in message
> news:359F429E-9876-4772-821A-063E185277B0@microsoft.com...
> > 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" <Joel> wrote in message
> >> news:A04725E8-A78F-4257-B072-FBAFE2A4B689@microsoft.com...
> >> > 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.
> >
> >
> >>


>
 
S

Sue Mosher [MVP]

Still looking for your Outlook version.

Sue Mosher

"Joel" <Joel> wrote in message

news:7AB91D9B-9E2C-4FA9-A428-93EE22D4CCD1@microsoft.com...
> 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" <Joel> wrote in message
> > news:359F429E-9876-4772-821A-063E185277B0@microsoft.com...
> > > 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" <Joel> wrote in message
> > >> news:A04725E8-A78F-4257-B072-FBAFE2A4B689@microsoft.com...
> > >> > 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.
> > >
>> >
>> >>

>

>
>>
 
S

Sm9lbA

need to work with 2003 & 2007

"Sue Mosher [MVP]" wrote:


> Still looking for your Outlook version.
> > Sue Mosher
> > >

> "Joel" <Joel> wrote in message
> news:7AB91D9B-9E2C-4FA9-A428-93EE22D4CCD1@microsoft.com...
> >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" <Joel> wrote in message
> >> news:359F429E-9876-4772-821A-063E185277B0@microsoft.com...
> >> > 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" <Joel> wrote in message
> >> >> news:A04725E8-A78F-4257-B072-FBAFE2A4B689@microsoft.com...
> >> >> > 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.
> >> >
> >> >
> >> >
> >
> >
> >>


>
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
W One contact with Multiple Email Addresses Using Outlook 2
J multiple external addresses on Exchange 2007 contact? Exchange Server Administration 4
M possible to search Outlook for multiple email addresses at once? Using Outlook 1
A Sending Emails Through Outlook From Multiple Email Addresses Using Outlook 1
G Multiple email addresses (Outlook 2002). All emails (both addresses) go into the one inbox. How do i Using Outlook 3
G Outlook Social Connector and multiple email addresses Using Outlook 3
R Possible to setup multiple reply from addresses in the same Outlook profile? Using Outlook 1
J How do I send an email from multiple email addresses in Outlook? Using Outlook 3
O Cannot send emails to multiple addresses Using Outlook 2
L merge multiple email addresses to one pane Using Outlook 4
A Multiple E-mail Addresses - Which was addressee? Using Outlook 2
I Outlook 2010 Spam Filter on multiple email addresses Using Outlook 4
D Outlook 2007: "the Operation Failed" on Send to Multiple addresses Using Outlook 6
A Multiple signatures Using Outlook 2
O Outlook tasks - Add text column with multiple lines Using Outlook 3
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
L Multiple Inboxes Using Outlook 3
RBLampert Accessing Outlook accounts from multiple computers Using Outlook 8
Martull Forced signature when multiple accounts exist Outlook VBA and Custom Forms 4
T Outlook 2010 Correct way to map multiple contact fields Using Outlook 4
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
papa.deblanc Multiple Instances Using Outlook 6
V Multiple Calendars in Outlook To-Do Bar; Office 365 Using Outlook 3
A Add multiple servers "on behalf of" email to "safe senders" list. Using Outlook 1
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
D [TOOL] QuickModules to sort emails very quickly to multiple folders Outlook VBA and Custom Forms 1
A Multiple Outlook Invites Received by One Person Using Outlook 4
N Selecting multiple calendar items Using Outlook 4
F Sharepoint tasks from multiple accounts in To-Do List Using Outlook 8
N Multiple instances of Outlook on Start Menu Using Outlook 2
D Edit Subject (Multiple Accounts) Outlook VBA and Custom Forms 5
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
L Need to import multiple Outlook files to Office 365 Account Using Outlook 4
B Deleting multiple accounts Using Outlook 1
I Dialog called up multiple times when saving emails from macro Outlook VBA and Custom Forms 2
M Multiple spurious empty folders appear in archive files Using Outlook 3
G Bcc help - Preventing multiple forwards from a bcc'd distribution group Using Outlook 1
J Outlook Rules - Changing auto-submit address in multiple rules, according to rule name Outlook VBA and Custom Forms 0
F Send multiple batch tasks to single person Using Outlook 3
M Multiple workstations and multiple accounts - keep in sync? Using Outlook.com accounts in Outlook 2
S How to extract mail items from multiple folders and shared mailboxes? Outlook VBA and Custom Forms 0
A open Outlook with multiple windows. Using Outlook 0
M Ensure the same inbox view across multiple outlook instances Using Outlook.com accounts in Outlook 7
D Multiple mailboxes, 1 certificate. How to prevent message "Invalid Certificate" Using Outlook 0
R Using Multiple Accounts in Outlook Using Outlook 3
D Multiple Accounts Issue Receiving Emails in 2016 Using Outlook 0
M Multiple User Defined Fields that can be added, changed, updated using VBA and user form Outlook VBA and Custom Forms 0
Diane Poremsky Combine and Print Multiple Outlook Calendars New Slipstick.com Articles 0
Similar threads


















































Top