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


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

>

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


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

>

>
>>
 
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.
Similar threads
Thread starter Title Forum Replies Date
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
D Outlook 2007: "the Operation Failed" on Send to Multiple addresses Using Outlook 6
chummy Open multiple Hyperlinks to download files Outlook VBA and Custom Forms 3
R Select Multiple Graphic Objects Using Outlook 0
Hornblower409 Automatically or Manually Backup Multiple Versions of VbaProject.OTM Outlook VBA and Custom Forms 1
B Modify VBA to create a RULE to block multiple messages Outlook VBA and Custom Forms 0
C Outlook 365 Multiple different Signatures on Shared Mailbox Using Outlook 0
R Advise on using multiple instances of network files based on customers Outlook VBA and Custom Forms 8
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
C How to search for items in Outbox with multiple accounts? Using Outlook 20
K How to share multiple calendar items Using Outlook 1
K Multiple copies of task being created Using Outlook 2
S Auto forward for multiple emails Outlook VBA and Custom Forms 0
K Multiple Rules on Single Email Using Outlook 2
Cathy Rhone gmail listed multiple times Using Outlook 3
H Synchronize contacts and calendars across multiple devices Using Outlook 0
V Outlook 2016 Multiple recurring tasks getting created Using Outlook 0
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
Globalforester ItemAdd Macro - multiple emails Outlook VBA and Custom Forms 3
J Multiple calendars Using Outlook 0
C Multiple emails Using Outlook 8
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
E Asking user to select multiple options in a list in an email Outlook VBA and Custom Forms 0
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
M 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

Similar threads

Back
Top