【发布时间】:2011-08-30 09:04:22
【问题描述】:
每当有新邮件到达 Outlook 时,我都会尝试运行一个函数。我一直在做一些搜索,但每次收到电子邮件时我都找不到触发代码的方法。有没有我可以利用的新邮件事件?
我向它添加了一个简单的MsgBox,以便能够查看事件是否正在触发,但它似乎没有工作。我将此代码放在ThisOutlookSession 模块中。有什么建议吗?这是我的代码。
Public WithEvents myOlApp As Outlook.Application
Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.Application")
End Sub
Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Dim x As Integer
Set myExplorers = myOlApp.Explorers
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
MsgBox ("Test")
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
skipif:
Next x
End If
On Error GoTo 0
myFolder.Display
End Sub
【问题讨论】:
-
当有人提供了解决您问题的答案时,单击答案旁边的小 V 将其标记为已接受。这样,您就可以向阅读本文的任何人发出信号,这就是解决方案,并且您的问题已经解决。