Explorer.Selection Property

Outlook Developer Reference

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

Syntax

expression.Selection

expression   A variable that represents 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.

Visual Basic for Applications
  Sub GetSelectedItems()
    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 = Application.ActiveExplorer
    Set myOlSel = myOlExp.Selection
    For x = 1 To myOlSel.Count
        MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & ";"
    Next x
    MsgBox MsgTxt
End Sub

See Also