Selection Property

Returns a **Selection**object consisting of one or more items selected in the current view.

expression**.Selection**

*expression   * Required. An expression that returns an Explorer object.

Remarks

If the current folder is a file-system folder, or if Microsoft Outlook Today or any folder with a Web view is currently displayed, this property returns an empty collection.

Also if a group header is selected, the Count property on the selection returns zero.

Example

The following Microsoft Visual Basic/Visual Basic for Applications (VBA) example uses the Count property and Item method of the Selection collection returned by the Selection property to display the senders of all messages selected in the active explorer window. To run this example without any errors, select mail items only. Selecting an item that does not have the SenderName property will result in an error.

Sub GetSelectedItems()
    Dim myOlApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Outlook.Selection
    Dim MsgTxt As String
    Dim x As Integer
    MsgTxt = "You have selected items from: "
    Set myOlExp = myOlApp.ActiveExplorer
    Set myOlSel = myOlExp.Selection
    For x = 1 To myOlSel.Count
        MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & ";"
    Next x
    MsgBox MsgTxt
End Sub

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

Sub CommandButton1_Click()
 MsgTxt = "You have selected items from: "
 Set myOlSel = Application.ActiveExplorer.Selection
 For x = 1 To myOlSel.Count
     MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & ";"
 Next x
 MsgBox MsgTxt
End Sub

Applies to | Explorer Object

See Also | Display Method | SelectionChange Event