共用方式為


Outlook) (交談物件

表示交談,其中包含儲存在一或多個資料夾和存放區的一或多個專案。

註解

Conversation 物件是抽象的彙總物件。 雖然交談可以包括不同類型的項目,Conversation 物件並不對應於特定的基礎 MAPI IMessage 物件。

交談代表一個或多個資料夾與存放區中的一個或多個項目。 如果您將交談中的專案移至 [ 刪除的郵件 ] 資料夾,然後使用 GetChildrenGetRootItemsGetTable 方法列舉交談,則專案將不會包含在傳回的物件中。

若要為現有的交談取得 Conversation 物件,請使用項目的 GetConversation 方法。

您可以藉由呼叫 SetAlwaysAssignCategoriesSetAlwaysDeleteSetAlwaysMoveToFolder 方法,將動作套用至交談中的專案。 這些動作中每一項都會在呼叫方法時自動套用至交談中的所有項目,而只要動作仍適用於交談,也會套用至交談中的未來項目。 Conversation 物件上沒有明確的儲存方法。

而且,當您套用動作至交談中的項目時,會發生對應的事件。 例如,當您呼叫SetAlwaysAssignCategories時,會發生Items物件的ItemChange事件,而Folder物件的BeforeItemMove事件則會在您呼叫SetAlwaysMoveToFolder 時發生。

範例

The following managed code is written in C#. To run a .NET Framework managed code sample that needs to call into a Component Object Model (COM), you must use an interop assembly that defines and maps managed interfaces to the COM objects in the object model type library. For Outlook, you can use Visual Studio and the Outlook Primary Interop Assembly (PIA). Before you run managed code samples for Outlook 2013, ensure that you have installed the Outlook 2013 PIA and have added a reference to the Microsoft Outlook 15.0 Object Library component in Visual Studio. 您應該使用 Office Developer Tools for Visual Studio) ,在 Outlook 增益集 (類別中使用下列程式碼 ThisAddIn 。 程式碼中的Application物件必須是 所 ThisAddIn.Globals 提供的受信任 Outlook應用程式物件。 如需使用 Outlook PIA 開發受控 Outlook 解決方案的詳細資訊,請參 閱 MSDN 上的歡迎使用 Outlook 主要 Interop 元件參考

下列程式碼範例假設檔案總管視窗中選取的專案是訊息項目。 程式碼範例會取得與所選訊息項目相關聯的交談,並列舉該交談中的每個專案,顯示專案的主旨。 方法 DemoConversation 會呼叫所選訊息項目的 GetConversation 方法,以取得相關聯的 Conversation 物件。 DemoConversation然後呼叫 Conversation物件的GetTableGetRootItems方法,分別取得Table物件和SimpleItems集合。 DemoConversation 會呼叫迴圈方法 EnumerateConversation 來列舉和顯示該交談中每個專案的主旨。

void DemoConversation() 
{ 
 object selectedItem = 
 Application.ActiveExplorer().Selection[1]; 
 // This example uses only 
 // MailItem. Other item types such as 
 // MeetingItem and PostItem can participate 
 // in the conversation. 
 if (selectedItem is Outlook.MailItem) 
 { 
 // Cast selectedItem to MailItem. 
 Outlook.MailItem mailItem = 
 selectedItem as Outlook.MailItem; 
 // Determine the store of the mail item. 
 Outlook.Folder folder = mailItem.Parent 
 as Outlook.Folder; 
 Outlook.Store store = folder.Store; 
 if (store.IsConversationEnabled == true) 
 { 
 // Obtain a Conversation object. 
 Outlook.Conversation conv = 
 mailItem.GetConversation(); 
 // Check for null Conversation. 
 if (conv != null) 
 { 
 // Obtain Table that contains rows 
 // for each item in the conversation. 
 Outlook.Table table = conv.GetTable(); 
 Debug.WriteLine("Conversation Items Count: " + 
 table.GetRowCount().ToString()); 
 Debug.WriteLine("Conversation Items from Table:"); 
 while (!table.EndOfTable) 
 { 
 Outlook.Row nextRow = table.GetNextRow(); 
 Debug.WriteLine(nextRow["Subject"] 
 + " Modified: " 
 + nextRow["LastModificationTime"]); 
 } 
 Debug.WriteLine("Conversation Items from Root:"); 
 // Obtain root items and enumerate the conversation. 
 Outlook.SimpleItems simpleItems 
 = conv.GetRootItems(); 
 foreach (object item in simpleItems) 
 { 
 // In this example, only enumerate MailItem type. 
 // Other types such as PostItem or MeetingItem 
 // can appear in the conversation. 
 if (item is Outlook.MailItem) 
 { 
 Outlook.MailItem mail = item 
 as Outlook.MailItem; 
 Outlook.Folder inFolder = 
 mail.Parent as Outlook.Folder; 
 string msg = mail.Subject 
 + " in folder " + inFolder.Name; 
 Debug.WriteLine(msg); 
 } 
 // Call EnumerateConversation 
 // to access child nodes of root items. 
 EnumerateConversation(item, conv); 
 } 
 } 
 } 
 } 
} 
 
 
void EnumerateConversation(object item, 
 Outlook.Conversation conversation) 
{ 
 Outlook.SimpleItems items = 
 conversation.GetChildren(item); 
 if (items.Count > 0) 
 { 
 foreach (object myItem in items) 
 { 
 // In this example, only enumerate MailItem type. 
 // Other types such as PostItem or MeetingItem 
 // can appear in the conversation. 
 if (myItem is Outlook.MailItem) 
 { 
 Outlook.MailItem mailItem = 
 myItem as Outlook.MailItem; 
 Outlook.Folder inFolder = 
 mailItem.Parent as Outlook.Folder; 
 string msg = mailItem.Subject 
 + " in folder " + inFolder.Name; 
 Debug.WriteLine(msg); 
 } 
 // Continue recursion. 
 EnumerateConversation(myItem, conversation); 
 } 
 } 
} 
 

方法

名稱
ClearAlwaysAssignCategories
GetAlwaysAssignCategories
GetAlwaysDelete
GetAlwaysMoveToFolder
GetChildren
GetParent
GetRootItems
GetTable
MarkAsRead
MarkAsUnread
SetAlwaysAssignCategories
SetAlwaysDelete
SetAlwaysMoveToFolder
StopAlwaysDelete
StopAlwaysMoveToFolder

屬性

名稱
Application
Class
ConversationID
Parent
Session

另請參閱

Outlook 物件模型參考交談物件成員

支援和意見反應

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