如何进行"setAlwaysMoveConversation"正常工作吗? [英] How do I make a "setAlwaysMoveConversation" that works properly?
问题描述
在Outlook中,如果我激活始终在此对话中移动邮件",它将:
In Outlook, if I activate "always move messages in this conversation", it will:
- 将对话中的所有消息移动到目标文件夹,包括已发送邮件 中的消息
- 从那一刻起,该对话中所有已收到的邮件将被移至目标文件夹.但是,该会话中所有已发送的邮件将保留在已发送邮件文件夹中.
- Move all of the messages in the conversation to the target folder, including those in Sent Items
- From that moment on, all messages received in that conversation will be moved to the target folder. However, all messages sent in that conversation will remain in the Sent Items folder.
我希望第1步排除已发送邮件中的邮件.
I want step 1 to exclude those already in sent items.
背景:我们正在使用共享邮箱,对于我们每个人来说,我都无法快速采取行动,因为其中会有太多的人. 因此,我创建了一个带有按钮的子控件,该按钮使用用户名并将其移动(使总是移动)到相应的文件夹.
Background: we're using a shared mailbox, and I can't have a quick step for each of us because there will be too many of them. So I made a sub with a button that takes the username and moves (enables always move) to the corresponding folder.
但是,我希望保留已发送的项目-这是否可行,还是我应该建立自己的"alwaysMoveMessages"功能?
But, I want the sent items to remain - is this possible, or should I make my own "alwaysMoveMessages" function?
谢谢!
推荐答案
使用 Conversation.GetTable 一个Table对象,其中包含会话中的所有项目.
Work with Conversation.GetRootItems A SimpleItems
collection that includes the root item or all root items of the conversation and Conversation.GetTable A Table object that contains all Items in the conversation.
示例代码
Option Explicit
Sub MoveConv()
Dim olNs As NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim SelectedItem As Object
Dim Item As Outlook.MailItem ' Mail Item
Dim Folder As Outlook.MAPIFolder ' Current Item's Folder
Dim Conversation As Outlook.Conversation ' Get the conversation
Dim ItemsTable As Outlook.Table ' Conversation table object
Dim MailItem As Object
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
' On Error GoTo MsgErr
' // Must Selected Item.
Set SelectedItem = Application.ActiveExplorer.Selection.Item(1)
' // If Item = a MailItem.
If TypeOf SelectedItem Is Outlook.MailItem Then
Set Item = SelectedItem
Set Conversation = Item.GetConversation
If Not IsNull(Conversation) Then
Set ItemsTable = Conversation.GetTable
For Each MailItem In Conversation.GetRootItems ' Items in the conv.
If TypeOf MailItem Is Outlook.MailItem Then
Set Item = MailItem
Set Folder = Item.Parent
Set SubFolder = Inbox.Folders("Temp") ' Move to Temp Folder
Debug.Print Item.ConversationID & " In Folder " & Folder.Name
GetConv Item, Conversation
Item.Move SubFolder
End If
Next
End If
End If
MsgErr_Exit:
Set olNs = Nothing
Set Inbox = Nothing
Set Item = Nothing
Set SelectedItem = Nothing
Set MailItem = Nothing
Exit Sub
'// Error information
MsgErr:
MsgBox "Err." _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume MsgErr_Exit
End Sub
Function GetConv(Item As Object, Conversation As Outlook.Conversation)
Dim Items As Outlook.SimpleItems
Dim MailItem As Object
Dim Folder As Outlook.Folder
Dim olNs As NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Conversation.GetChildren(Item)
If Items.Count > 0 Then
For Each MailItem In Items
If TypeOf MailItem Is Outlook.MailItem Then
Set Item = MailItem
Set Folder = Item.Parent
Set SubFolder = Inbox.Folders("Temp")
Debug.Print Item.ConversationID & " In Folder " & Folder.Name
Item.Move SubFolder
End If
GetConv Item, Conversation
Next
End If
End Function
这篇关于如何进行"setAlwaysMoveConversation"正常工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!