Vba 在Access中处理Outlook邮件项目发送事件

Vba 在Access中处理Outlook邮件项目发送事件,vba,ms-access,outlook,Vba,Ms Access,Outlook,我正在试图找到一种方法,从Access捕获Outlook中的邮件项.Send事件。我已经创建了一个类来设置对象,并且运行良好,但是事件处理程序似乎没有做任何事情 下面是我创建的类(名为OutlookHandler): 下面是我创建该类实例的函数: Public Function test() Dim ol As New OutlookHandler With ol.msg .To = "mike@anywhere.com"

我正在试图找到一种方法,从Access捕获Outlook中的
邮件项.Send
事件。我已经创建了一个类来设置对象,并且运行良好,但是事件处理程序似乎没有做任何事情

下面是我创建的类(名为
OutlookHandler
):

下面是我创建该类实例的函数:

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
时,会创建并显示电子邮件。当我在电子邮件中点击send时,电子邮件会发送,但消息框不会创建。我缺少什么?

您需要以这种方式公开您的
ol变量

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

我不认为
ol变量实际上必须是公共的。暗显后确实需要将其设置为新实例,但您可以在测试中暗显它function@HelloW-如果您在
test
内部
Dim ol
,则它不是全局的,一旦
test
完成,它就会超出范围。一旦超出范围,就无法响应任何事件。@TimWilliams感谢您的解释。我没有看到那个细节。
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