Nested distribution lists

H

Hal

I know how to make a new DL and add users to a DL via vba but how do I make a
nested distribution list ?

Regards
 
E

Eric Legault [MVP - Outlook]

Create a dummy e-mail message and address it to the DL you want to nest.
Then retrieve that DL's Recipient object from the MailItem.Recipients
collection and pass it to the DistributionList.AddMember method.
 
E

Eric Legault [MVP - Outlook]

Actually, there's another way to do this without creating a dummy e-mail.
This code illustrates retrieving a DL named "TestDistributionList" and adding
another existing DL named "AnotherDistributionList" to it:

Dim objNS As Outlook.NameSpace
Dim objDL As Outlook.DistListItem
Dim objContacts As Outlook.MAPIFolder
Dim objR As Outlook.Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
Set objDL = objContacts.Items("TestDistributionList")
Set objR = objNS.CreateRecipient("AnotherDistributionList")

objR.Resolve
objDL.AddMember objR
objDL.Save

Set objDL = Nothing
Set objNS = Nothing
Set objContacts = Nothing
Set objR = Nothing

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 
H

Hal

Eric

Your code does not produce a DL named AnotherDistributionList in
TestDistributionList. I have tested in on a pst and when connected to
exchange.

Hal
 
Top