Outlook) (交談物件

代表包含儲存在一或多個資料夾與存放區中的一或多個項目的交談。

註解

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

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

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

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

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

範例

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. 您應該在 Outlook 增益集類別中使用 ThisAddIn 以下代碼 (使用適用於 Visual Studio) 的 Office 開發人員工具。 程式碼中的 Application 物件必須是由 提供信任ThisAddIn.Globals的 Outlook Application 物件。 如需使用 Outlook PIA 開發受管理 Outlook 解決方案的詳細資訊,請參閱 MSDN 上的 歡迎使用 Outlook 主要互通組件參考 。

下列程式碼範例假設 [檔案總管] 視窗中選取的項目是郵件項目。 程式碼範例會取得與所選郵件項目相關聯的交談,並列舉該交談中的每個項目,並顯示項目的主旨。 DemoConversation此方法會呼叫所選郵件項目的 GetConversation 方法來取得關聯的 Conversation 物件。 DemoConversation然後呼叫 Conversation 物件的 GetTable 和 GetRootItems 方法,以分別取得 Table 物件和 SimpleItems 集合。 DemoConversation 呼叫 Recurrent 方法 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 支援與意見反應。