共用方式為


Outlook) (Explorer.Selection 屬性

會傳回 Selection 物件,其中包含在總管視窗中選取的專案。 唯讀。

語法

運算式選擇

表達 代表 'Explorer' 物件的變數。

註解

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

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

另請參閱

Explorer 物件

支援和意見反應

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