Check for the distribution list existence

  • Thread starter Thread starter paresh
  • Start date Start date
P

paresh

Hi,

I have written attached code for creating distribution list and
adding/enumerating it's members. I want to put a check before creating
distribution list or adding members into existed distribution list.
1. If DL is exists then it should not create it again and it should
add member to existed DL.
2. If DL is not exists then it should create it and add member.

Thanks.

Dim DL As Outlook.DistListItem
Dim rcp As Outlook.Recipient
Set DL = Application.CreateItem(olDistributionListItem)
DL.DLName = "MyList"

Set rcp = Application.Session.CreateRecipient(userName)
rcp.Resolve
If rcp.Resolved = True Then
DL.AddMember rcp
End If

DL.Save
 
You need to go to every folder where a DL might exist, starting with the
default Contacts folder. You can then filter the Items collection for each
of those folders for distribution list items and see if any already exist
that match whatever criteria you are using to determine existence, such as
name.

You can filter the Items collections on the MessageClass property.
 
Back
Top