You cannot do that in the Outlook Object Model.
You can try to use Redemption, which exposes RDODistListItem.AddContact method - it will let you pass ContactItem as well as DistListItem object as a parameter.
How to Add a Distribution List Item to a Distribution List?
-
17-01-2022 - |
Question
I am attempting to add multiple child distribution lists as members of a parent distribution list through Outlook 2010 VBA.
The basic code that Sue Mosher posted online (where objItem is the child DL, as discovered via a For/Next loop) is:
Set objRecipient = Application.Session.CreateRecipient(objItem.Subject)
objRecipient.Resolve
objDistributionList.AddMember objRecipient
This is adding the child DL as "contact" rather than a member linking to the original child DL.
When I open the member, which is supposed to be the child DL within the parent DL, it appears as an email contact with an "UNKNOWN" email address.
La solution
Autres conseils
It turns out it actually is possible to do this within VBA, though it is a bit roundabout and I can't decipher why it works.
By adding a child distribution list to the 'to' field of a Mail Item object, it resolves the recipients of the Mail Item to a distribution list. You can then add those recipients to a parent distribution list. Note that this requires the Child List to still exist separately, ie. if the Child List is deleted, the Parent List will not be able to find it
Sub NestedDistLists()
Dim outApp As Object
Dim outMail As Object
Dim distRecipients As Object
Dim distListChild As Object
Dim distListParent As Object
Set outApp = CreateObject("Outlook.Application")
Set outMail = outApp.createItem(0)
Set distListChild = outApp.createItem(7)
Set distListParent = outApp.createItem(7)
Set distRecipients = outMail.recipients
distListChild.dlName = "Test Child"
distRecipients.Add "john@example.com"
distRecipients.resolveall
distListChild.addmembers distRecipients
distListChild.Save
outMail.to = distListChild
distListParent.dlName = "Test Parent"
distListParent.addmembers distRecipients
distListParent.Save
distListParent.display
End Sub