我正试图找到一种方法来从Access中捕获Outlook中的MailItem.Send
事件。我已经创建了一个设置对象的类,并且工作正常,但事件处理程序似乎没有做任何事情。
这是我创建的类(名为OutlookHandler
):
Public WithEvents app As Outlook.Application
Public WithEvents msg As Outlook.MailItem
Private Sub Class_Initialize()
Set app = CreateObject("Outlook.Application")
Set msg = app.CreateItem(olMailItem)
End Sub
Private Sub msg_Send(Cancel As Boolean)
MsgBox "Message Sent!"
End Sub
这是我创建该类实例的函数:
Public Function test()
Dim ol As New OutlookHandler
With ol.msg
.To = "mike@anywhere.com"
.Subject = "outlook event test"
.Display
End With
End Function
当我运行test
时,电子邮件会创建并显示。当我点击发送电子邮件时,电子邮件会发送但消息框永远不会创建。我错过了什么?
答案 0 :(得分:2)
您需要以这种方式公开ol variable
:
Dim ol As OutlookHandler
Public Function test()
'Dim ol As New OutlookHandler
Set ol = New OutlookHandler
With ol.msg
.To = "mike@anywhere.com"
.Subject = "outlook event test"
.Display
End With
End Function