AddMembers Method

Microsoft Outlook Visual Basic

Adds new members to a distribution list.

expression.AddMembers(Recipients)

expression    Required. An expression that returns a DistListItem object.

Recipients    Required Recipients object. The members to be added to the distribution list.

Example

This Microsoft Visual Basic/Visual Basic for Applications (VBA) example creates a new distribution list and adds the current user and 'Dan Wilson' to the list. If the specified recipient is not valid, the AddMember method will fail. Therefore, to run this example, replace 'Dan Wilson' with a valid recipient name.

Sub AddNewMembers()
	Dim myOlApp As New Outlook.Application
	Dim myNameSpace As Outlook.NameSpace
	Dim myDistList As Outlook.DistListItem
	Dim myTempItem As Outlook.MailItem
	Dim myRecipients As Outlook.Recipients
	Set myNameSpace = myOlApp.GetNamespace("MAPI")
	Set myDistList = myOlApp.CreateItem(olDistributionListItem)
	Set myTempItem = myOlApp.CreateItem(olMailItem)
	Set myRecipients = myTempItem.Recipients
	myDistList.DLName = _
		InputBox("Enter the name of the new distribution list")
	myRecipients.Add myNameSpace.CurrentUser.Name
	myRecipients.Add "Dan Wilson"
	myRecipients.ResolveAll
	myDistList.AddMembers myRecipients
	myDistList.Save
	myDistList.Display
End Sub
		

If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myNameSpace = Application.GetNamespace("MAPI")
Set myDistList = Application.CreateItem(7)
Set myTempItem = Application.CreateItem(0)
Set myRecipients = myTempItem.Recipients
myDistList.DLName = _
    InputBox("Enter the name of the new distribution list")
myRecipients.Add myNameSpace.CurrentUser.Name
myRecipients.Add "Dan Wilson"
myRecipients.ResolveAll
myDistList.AddMembers myRecipients 
myDistList.Save
myDistList.Display