Class Recipients (Outlook VBA)

Contains a collection of Recipient objects for an Outlook item. To use a Recipients class variable it first needs to be instantiated, for example


Dim rcps as Recipients
Set rcps = Session.CreateSharingItem.Reply.Recipients

For Each

Here is an example of processing the Recipients items in a collection.


Dim rcp As Recipient
For Each rcp In Recipients
	
Next rcp

Add

Creates a new recipient in the Recipients collection.

Add (Name)

Name: The name of the recipient; it can be a string representing the display name, the alias, or the full SMTP email address of the recipient.


Sub CreateStatusReportToBoss() 

    Dim myItem As Outlook.MailItem 
    Dim myRecipient As Outlook.Recipient 

    Set myItem = Application.CreateItem(olMailItem) 
    Set myRecipient = myItem.Recipients.Add("Dan Wilson") 
    myItem.Subject = "Status Report" 
    myItem.Display 

End Sub

Class

Returns an OlObjectClass constant indicating the object's class. Here you can find possible values for OlObjectClass.


Dim oocsClass As OlObjectClass
oocsClass = Session.CreateSharingItem.Reply.Recipients.Class

Count

Returns a Long indicating the count of objects in the specified collection.


Dim lngCount As Long
lngCount = Session.CreateSharingItem.Reply.Recipients.Count

Item

Returns a Recipient object from the collection.

Item (Index)

Index: Either the index number of the object, or a value used to match the default property of an object in the collection.


Dim rcp As Recipient
Set rcp = Session.CreateSharingItem.Reply.Recipients(Index:=1)

Remove

Removes an object from the collection.

Remove (Index)

Index: The 1-based index value of the object within the collection.


Dim lngIndex As Long: lngIndex = 
Session.CreateSharingItem.Reply.Recipients.Remove Index:=lngIndex

ResolveAll

Attempts to resolve all the Recipient objects in the Recipients collection against the Address Book.


Sub CheckRecipients() 
 
 Dim MyItem As Outlook.MailItem 
 
 Dim myRecipients As Outlook.Recipients 
 
 Dim myRecipient As Outlook.Recipient 
 
 
 
 Set myItem = Application.CreateItem(olMailItem) 
 
 Set myRecipients = myItem.Recipients 
 
 myRecipients.Add("Aaron Con") 
 
 myRecipients.Add("Nate Sun") 
 
 myRecipients.Add("Dan Wilson") 
 
 If Not myRecipients.ResolveAll Then 
 
 For Each myRecipient In myRecipients 
 
 If Not myRecipient.Resolved Then 
 
 MsgBox myRecipient.Name 
 
 End If 
 
 Next 
 
 End If 
 
End Sub

Session

Returns the NameSpace object for the current session.

The Session property and the GetNamespace method can be used interchangeably to obtain the NameSpace object for the current session. Both members serve the same purpose. For example, the following statements do the same function: