Resolving distribution list in Outlook VBA

1.8k views Asked by At

I am trying to create an email using VBA which pulls its recipients from a Public Folder with Distribution list.

I have the below code which works except it does not resolve the list, the recipient remains as a string.

Sub Email()

Dim list As Outlook.DistListItem
Dim oAPP                       As Object
Dim oItem                      As Object
Const olMailItem               As Long = 0

Set list = Application.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("Planning Weekly Distribution List").Items.Item("Test")

Set oAPP = CreateObject("Outlook.Application")
Set oItem = oAPP.CreateItem(olMailItem)
With oItem
     .Display
End With

With oItem
    .BCC = list
    .Subject = "hey"
    .HTMLBody = Body & "<br>" & .HTMLBody
    .Display
End With


End Sub
1

There are 1 answers

5
Dmitry Streblechenko On BEST ANSWER

Was "Planning Weekly Distribution List" folder added as the Outlook address book (right click on the folder, Properties, Outlook Address Book)? If yes, just set the BCC property to "test" - Outlook will resolve the name (assuming it is unambiguous).

If not, you will need to add the DL members as recipients one at a time.

To make sure the folder is used by the Outlook Address Book, set the MAPIFolder.ShowAsOutlookAB property.