我需要知道如何一次移动对话中的所有消息。
我的宏目前正在阅读
Sub Archive()
Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive")
For Each Msg In ActiveExplorer.Selection
Msg.UnRead = False
Msg.Move ArchiveFolder
Next Msg
End Sub
但这只会移动最新消息......并且只有当对话完全崩溃时!当谈话扩大时,我无法存档。
答案 0 :(得分:10)
Paul-Jan让我走上了正确的道路,所以我给了他答案。这是我真正糟糕的VBA版本(我缺少一些类型转换,检查)。但它确实适用于折叠和扩展的邮件对话。
Sub ArchiveConversation()
Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive")
Set Conversations = ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
For Each Header In Conversations
Set Items = Header.GetItems()
For i = 1 To Items.Count
Items(i).UnRead = False
Items(i).Move ArchiveFolder
Next i
Next Header
End Sub
答案 1 :(得分:3)
如果你想处理对话,你必须明确地这样做。您可以使用 MailItem.GetConversation 从MailItem转到其对话,但您最好直接使用对话。
你做的是:
以下C#代码说明了这一点,并且移植到VBA应该很简单。
Outlook.Selection selection = Application.ActiveExplorer().Selection;
Outlook.Selection convHeaders = selection.GetSelection( Outlook.OlSelectionContents.olConversationHeaders) as Outlook.Selection;
foreach (Outlook.ConversationHeader convHeader in convHeaders)
{
Outlook.SimpleItems items = convHeader.GetItems();
for (int i = 1; i <= items.Count; i++)
{
if (items[i] is Outlook.MailItem)
{
Outlook.MailItem mail = items[i] as Outlook.MailItem;
mail.UnRead = false;
mail.Move( archiveFolder );
}
// else... not sure how if you want to handle different types of items as well }
}
答案 2 :(得分:3)
安东尼的回答
Sub Archive()
Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive")
Dim IsMessage As Integer
IsMessage = 0
For Each Msg In ActiveExplorer.Selection
Msg.Move ArchiveFolder
IsMessage = 1
Next Msg
If IsMessage = 0 Then
Set Conversations = ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
For Each Header In Conversations
Set Items = Header.GetItems()
For i = 1 To Items.Count
Items(i).UnRead = False
Items(i).Move ArchiveFolder
Next i
Next Header
End If
End Sub