Outlook事件未触发 [英] Outlook events not firing

查看:196
本文介绍了Outlook事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据日历提醒关闭发送电子邮件.

I'm trying to send an email based on a calendar reminder going off.

我无法让VBA宏识别发生Outlook事件.

I'm having trouble getting VBA macros to recognize that an Outlook event has occurred.

我将此代码放在类模块"中:

I put this code in a Class Module:

Public WithEvents myOlApp As Outlook.Application

Sub Initialize_handler()
    Set myOlApp = Outlook.Application 'also tried with double quotes around "Outlook.Application"
End Sub

Private Sub myOlApp_Reminder(ByVal Item As Object)
    MsgBox ("test")
End Sub

Private Sub myOlApp_NewMail()
    MsgBox ("test")
End Sub

当我收到一封新电子邮件或提醒消失时,什么也没发生.

When I get a new email or a reminder goes off, nothing happens.

我已经在普通模块中对此宏进行了测试,并且可以正常工作:

I've tested with this macro in a normal module and it works:

Sub MsgBoxTest()
    MsgBox ("test")
End Sub

我在信任中心的启用所有宏"上有宏设置.

I have macro settings on "Enable all macros" in the Trust Center.

我已经搜索了google,stackoverflow,许多其他网站,并阅读了Microsoft.com上的文档.

I've searched google, stackoverflow, a bunch of other websites, and read the documentation on Microsoft.com.

我在运行Windows 10 Enterprise的PC上使用Outlook 2016.

I'm on Outlook 2016 on a PC running Windows 10 Enterprise.

推荐答案

对于此方法(通常在文档中使用),请手动运行Initialize_handler或在启动时在特殊的类模块ThisOutlookSession中运行它.

For this method, often used in documentation, run Initialize_handler manually or run it at startup in the special class module ThisOutlookSession.

Private Sub Application_Startup()
    Initialize_handler
End Sub

这篇关于Outlook事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆