Adding a contact to a Distribution List 
Author Message
 Adding a contact to a Distribution List

It does everything except add the person to the list.

Public Sub parse_party_pix()
Dim name_space As NameSpace, ol_app As Application ', email As MailItem,
pp_folder As MAPIFolder
Dim new_list As DistListItem ', email_body As MailItem
'Dim to_address As MailItem

Set ol_app = CreateObject("Outlook.Application")
Set name_space = ol_app.GetNamespace("MAPI")
Set all_folders = name_space.GetDefaultFolder(olFolderInbox)
Set pp_folder = all_folders.Folders("Party Pix")
Set pp_item = ol_app.CreateItem(olMailItem)

'create a new distribution list
Set new_list = ol_app.CreateItem(olDistributionListItem)
new_list.DLName = "Party Pix List"

q_email = pp_folder.Items.Count

x = 1
Do While x <= q_email
Set email = pp_folder.Items.Item(x)
email_body = email.Body
'discover how many caracters after the first close bracket
Set mail_to = CreateItem(olMailItem)
to_address = InStr(9, email_body, ")")
'Add address to list
to_address = Trim(Mid(email_body, to_address + 1))

Set rc = mail_to.Recipients.Add(to_address)
Set list_item = ol_app.CreateItem(olDistributionListItem)
list_item.AddMember rc
'MsgBox myRecipient
'new_list.AddMember Recipient:=to_address     '("ewst") ' myRecipient

'Debugging section---------
'MsgBox rc
'--------------------------

x = x + 1
'new_list.Display
Loop

new_list.Save

End Sub



Sat, 07 May 2005 07:16:44 GMT  
 Adding a contact to a Distribution List
Hi,

there are as far as I can see 2 thing wrong in your code.
1 is that you have 2 DistListItems, and you give 1 a name,
and you try to add members to the other? The 2nd is that
you can only add a Recipients collection to a
DistListItem, and the function is called
DistListItem.AddMembers(Recipients). If you would first
add all addresses to a tmp email (Mail.Recipients.Add),
you can then, after your complete do while loop add the
Mail.Recipients collection to the DistList.

Good luck.

Quote:
>-----Original Message-----
>It does everything except add the person to the list.

>Public Sub parse_party_pix()
>Dim name_space As NameSpace, ol_app As Application ',
email As MailItem,
>pp_folder As MAPIFolder
>Dim new_list As DistListItem ', email_body As MailItem
>'Dim to_address As MailItem

>Set ol_app = CreateObject("Outlook.Application")
>Set name_space = ol_app.GetNamespace("MAPI")
>Set all_folders = name_space.GetDefaultFolder
(olFolderInbox)
>Set pp_folder = all_folders.Folders("Party Pix")
>Set pp_item = ol_app.CreateItem(olMailItem)

>'create a new distribution list
>Set new_list = ol_app.CreateItem(olDistributionListItem)
>new_list.DLName = "Party Pix List"

>q_email = pp_folder.Items.Count

>x = 1
>Do While x <= q_email
>Set email = pp_folder.Items.Item(x)
>email_body = email.Body
>'discover how many caracters after the first close bracket
>Set mail_to = CreateItem(olMailItem)
>to_address = InStr(9, email_body, ")")
>'Add address to list
>to_address = Trim(Mid(email_body, to_address + 1))

>Set rc = mail_to.Recipients.Add(to_address)
>Set list_item = ol_app.CreateItem(olDistributionListItem)
>list_item.AddMember rc
>'MsgBox myRecipient
>'new_list.AddMember Recipient:=to_address     '("ewst") '
myRecipient

>'Debugging section---------
>'MsgBox rc
>'--------------------------

>x = x + 1
>'new_list.Display
>Loop

>new_list.Save

>End Sub

>.



Sat, 07 May 2005 17:01:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Add a contact to a Distribution List

2. adding a selected contact to a distribution list

3. Adding contacts to a distribution list

4. Adding contacts to my distribution list

5. Add Contacts to a PublicFolder Contact list

6. Outlook VBA:Add recipient to a distribution list in the Global Addtress List

7. getting distribution list from Contacts

8. Outlook Contacts - Distribution Lists

9. Members property of contact folder distribution lists - returns gobbledygook in lovely looking array

10. HELP please for contact from Distribution list

11. Help: Extracting Contact info from distribution list inspector

12. Distribution Lists - How to displaying individual contacts in To field

 

 
Powered by phpBB® Forum Software