我希望在收到不同邮箱的电子邮件时调用一组功能(如果邮件到达abc@outlook.com执行功能1,如果邮件到达def@outlook.com执行功能2) 我有一个邮箱的下面的代码,但我不知道如何扩展它也可以在没有冲突的情况下收听另一个邮箱。如何为多个邮箱设置侦听器? 任何帮助赞赏。谢谢
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' default local Inbox
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
'do Stuff to mailitem
End Sub
答案 0 :(得分:1)
只需添加另一个WithEvent即可观看其他文件夹:
Private WithEvents Items As Outlook.Items
Private WithEvents Items1 As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' default local Inbox
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
Set Items1 = objNS.Folders.Item("def@outlook.com").Folders.Item("Inbox").Folders.Item("ASubFolder").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
'do Stuff to mailitem
End Sub
Private Sub Items1_ItemAdd(ByVal Item As Object)
'do stuff.
End Sub