次の方法で共有


Selection.Item メソッド (Outlook)

選択範囲からMicrosoft Outlookの項目またはテーマのヘッダーを返します。

構文

Item (インデックス)

'Selection' オブジェクトを表す変数。

パラメーター

名前 必須 / オプション データ型 説明
Index 必須 バリアント型 (Variant) オブジェクトのインデックス番号、またはコレクションのオブジェクトの既定のプロパティに適合する値を指定します。

戻り値

指定した項目またはテーマのヘッダーを表す Object

注釈

Item メソッドの戻り値の型に関する仮定は行わないでください。コードは、複数の項目の種類または ConversationHeader オブジェクトを処理できる必要があります。 たとえば、Item メソッドは、Selection.Location プロパティの値に応じて、受信トレイ フォルダー内の AppointmentItemMailItemMeetingItem、または TaskItem を返すことができます。

Selection コレクションには、Selection オブジェクトの GetSelection メソッドで olConversationHeaders を指定した場合にのみ、ConversationHeader オブジェクトが含まれます。

次の Microsoft Visual Basic for Applications (VBA) の例では、アクティブなエクスプ ローラーで選択した各項目の差出人が表示されます。 アクティブなエクスプ ローラーで選択されているすべてのメッセージの送信者を表示するのには、 Count プロパティと Explorer.Selection プロパティによって返される Selection オブジェクトの 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 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

関連項目

Selection オブジェクト

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。