据我所知,我为你做了这个,它有效。您应该将它放在 Microsoft Outlook 对象 - ThisOutlookSession 模块中。
请注意,myolApp_ItemSend
除非您先运行,否则该事件永远不会触发enableEvents
。并且您需要确保每次关闭重新打开的 Outlook 时都启用它。这需要一些定制,但它应该给你一个大致的想法。
Option Explicit
Public WithEvents myolApp As Outlook.Application
Sub enableEvents()
Set myolApp = Outlook.Application
End Sub
Private Sub myolApp_ItemSend(ByVal item As Object, Cancel As Boolean)
Dim items As MailItem
Dim copyFolder As Outlook.Folder
Dim sentWith As String
'Identify sender address
If item.Sender Is Nothing Then
sentWith = item.SendUsingAccount.SmtpAddress
Else
sentWith = item.Sender.Address
End If
'Determin copy folder based on sendAddress
Select Case sentWith
Case "groupA@myCompany.com"
'get groupAMailbox's inbox
Set copyFolder = Application.GetNamespace("MAPI").folders("groupAMailbox").folders("Inbox")
Case "myE-mailAddress"
'get My inbox
Set copyFolder = Application.GetNamespace("MAPI").folders("myE-mailAddress").folders("Inbox")
End Select
'copy the Item
Dim copy As Object
Set copy = item.copy
'move copy to folder
copy.Move copyFolder
End Sub
编辑:看起来他们现在实际上已经将事件功能直接构建到 Outlook 的 Application 对象中,但是通过测试,您仍然必须执行我上面概述的操作。