PDA

View Full Version : VBA- - remove email Id from a Distribution List using VBA.



shivam749
08-29-2012, 04:30 AM
Urgent- I want remove a email id from a pdl using vba code, through excel. Please help?

It will be removed just for that particular mail sending process not permanently? Or if I can directly block some person in a pdl for receiving mails through the vba application

JP2112
09-14-2012, 12:11 PM
Here's an example that shows you how to perform certain activities with a distribution list. You can adapt it for your particular needs. I wrote this code in Outlook but you can set a reference to the Outlook object library in Excel if you want to use the code without modifying references.

Dim msg As Outlook.MailItem
Dim recip As Outlook.Recipient
Dim contacts As Outlook.Items
Dim dl As Outlook.DistListItem
Dim i As Long
Dim dlmember As Outlook.Recipient
' get currently displayed message
Set msg = ActiveInspector.CurrentItem
' assume DL is the only recipient
Set recip = msg.Recipients.item(1)
' get the distribution list in Contacts folder
Set contacts = Outlook.session.GetDefaultFolder(olFolderContacts).Items
Set dl = contacts.item(recip.name)
' loop through distribution list and show member names
For i = 1 To dl.MemberCount
Set dlmember = dl.GetMember(i)
Debug.Print "Member: " & dlmember.Address & " - " & dlmember.name
Next i

shivam749
09-15-2012, 12:37 AM
Thanks for your reply -

Can you please help me with this -
Set objDist = objFolder.Items(MyList)

I am getting error while debugging, it returns empty in 'objDist', which means Distribution List doesn't exist.

Should I be the owner of the PDL or it should be present in my contacts/outlook folder. I am all confused what is that I am missing.

I have tried a lot but not been able to get the solution please help.

If you can address this problem on 'shivamshukla@gmail.com', it would really help me.

Thanks
Shivam Shukla
shivamshukla749@gmail.com

JP2112
09-17-2012, 09:24 AM
What is objFolder pointing to?