Outlook) (Explorer.Selection 屬性

傳回包含檔案總管視窗中所選取項目的 Selection 物件。 唯讀。

語法

運算式。選取範圍

運算式 代表 'Explorer' 物件的變數。

註解

檔案總管中之選取範圍的位置可位於檢視清單中、[待辦事項列] 的約會清單或工作清單中,或者行事曆檢視的每日工作清單中。 如需詳細資訊,請參閱 [位置] 屬性。

Selection 屬性不包含任何交談標題物件。 呼叫 Selection.GetSelection 方法,提供 olConversationHeaders 做為引數,以取得在檔案總管中選取的交談標頭物件。

如果目前資料夾顯示資料夾首頁,此屬性即會傳回空集合。 此外,如果選取了像 Today 這樣的群組標頭或交談群組標頭,則傳回的 Selection 物件上的 Count 屬性為零。

範例

下列 Microsoft Visual Basic for Applications (VBA) 範例會顯示使用中檔案總管內每個選取項目的寄件者。 它會使用 Explorer.Selection 屬性所傳回之 Selection 物件的 Count 屬性和 Item 方法,顯示在使用中瀏覽器中所選取之所有郵件的寄件者。

Sub GetSelectedItems() 
 
 Dim myOlExp As Outlook.Explorer 
 
 Dim myOlSel As Outlook.Selection 
 
 Dim mySender As Outlook.AddressEntry 
 
 Dim oMail As Outlook.MailItem 
 
 Dim oAppt As Outlook.AppointmentItem 
 
 Dim oPA As Outlook.PropertyAccessor 
 
 Dim strSenderID As String 
 
 Const PR_SENT_REPRESENTING_ENTRYID As String = _ 
 
 "http://schemas.microsoft.com/mapi/proptag/0x00410102" 
 
 Dim MsgTxt As String 
 
 Dim x As Long 
 
 
 
 MsgTxt = "Senders of selected items:" 
 
 Set myOlExp = Application.ActiveExplorer 
 
 Set myOlSel = myOlExp.Selection 
 
 For x = 1 To myOlSel.Count 
 
 If myOlSel.Item(x).Class = OlObjectClass.olMail Then 
 
 ' For mail item, use the SenderName property. 
 
 Set oMail = myOlSel.Item(x) 
 
 MsgTxt = MsgTxt & oMail.SenderName & ";" 
 
 ElseIf myOlSel.Item(x).Class = OlObjectClass.olAppointment Then 
 
 ' For appointment item, use the Organizer property. 
 
 Set oAppt = myOlSel.Item(x) 
 
 MsgTxt = MsgTxt & oAppt.Organizer & ";" 
 
 Else 
 
 ' For other items, use the property accessor to get the sender ID, 
 
 ' then get the address entry to display the sender name. 
 
 Set oPA = myOlSel.Item(x).PropertyAccessor 
 
 strSenderID = oPA.GetProperty(PR_SENT_REPRESENTING_ENTRYID) 
 
 Set mySender = Application.Session.GetAddressEntryFromID(strSenderID) 
 
 MsgTxt = MsgTxt & mySender.Name & ";" 
 
 End If 
 
 Next x 
 
 Debug.Print MsgTxt 
 
End Sub

另請參閱

檔案總管物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。