Selection Property

Microsoft Outlook Visual Basic

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 Outlook Today or any folder with a current Web view is currently displayed, this property returns an empty collection.

Example

The following Microsoft Visual Basic/Visual Basic for Applications 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.

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

If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.

MsgTxt = "You have selected items from" & Chr(13) & Chr(13)
Set myOlSel = Application.ActiveExplorer.Selection
For x = 1 To myOlSel.Count
    MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & Chr(13)
Next 
MsgBox MsgTxt