如何使 application.reminder 事件起作用? [英] How do I make the application.reminder event work?
问题描述
我在类模块中有此代码 - 正如 msdn 和这个stackoverflow线程
I have this code in a class module - as stated to on msdn and on this stackoverflow thread
Public WithEvents objReminders As Outlook.Reminders
Private Sub Application_Startup()
Set objReminders = Application.Reminders
End Sub
Private Sub Application_Reminder(ByVal Item As Object)
Call Send_Email_Using_VBA
MsgBox ("Litigate!")
End Sub
我已尝试使用此线程 那也不会启动.
I have tried using the code at the bottom of this thread and that won't launch either.
我所能得到的只是 Outlook 的提醒弹出窗口.没有断点被击中,Msgbox 永远不会显示 - 即使我删除了函数调用.我重启了好几次都没有结果.
All I can get is outlook's reminders popup. No breakpoints are ever hit, the Msgbox never shows - even if I remove the function call. I have restarted it several times and I have no result.
我是否遗漏了一些重要的东西?
Am I missing something important?
推荐答案
您正在使用 WithEvents
来处理 objReminders
上的 Reminder
事件对象,但您没有声明要匹配的 subs.在我下面的代码中,请注意 objReminders_...
与您的 Application_...
子项.
You are using WithEvents
to handle your Reminder
events on the objReminders
object, but you are not declaring the subs to match. In my code below, please note the objReminders_...
vs. your Application_...
subs.
我在 Outlook 2003 中使用了您的代码(我没有 Office 2007,因此无法在那里进行测试),并得出以下结论:
I played with your code in Outlook 2003 (I do not have Office 2007, so I cannot test there), and came up with the following:
Public WithEvents objReminders As Outlook.Reminders
Private Sub objReminders_Snooze(ByVal ReminderObject As Reminder)
Call Send_Email_Using_VBA
MsgBox ("Litigate!")
End Sub
Private Sub Class_Initialize()
Set objReminders = Outlook.Reminders
End Sub
在普通代码模块中实现:
Implemented with this in a normal code module:
Sub test()
Dim rmd As New ReminderClass
rmd.objReminders.Item(1).Snooze 1 'Triggers objReminders_Snooze in class module
rmd.objReminders.Item(2).Snooze 1
End Sub
现在,这是在我明确调用的 Snooze
事件上触发的.但是,这也应该适用于您在事件首次出现时触发(据我所知,这不会在提醒从 Snooze
唤醒时触发).我没有设置任何提醒来测试 - 如果您还有其他困难,我会为此设置一些我自己的测试.
Now, this is triggering on the Snooze
event, which I explicitly call. However, this should also work for you to trigger when the event first comes up (this does not, as far as I can tell, trigger when a reminder wakes from a Snooze
). I did not have any reminders set up to test - if you have difficulties beyond this, I will set up a few of my own tests with regard to that.
Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
Call Send_Email_Using_VBA
MsgBox ("Litigate!")
End Sub
<小时>
更新:
在 2010 年玩弄这个之后,我发现以下方法有效(至少是火,但似乎一直在火):
After playing around with this in 2010, I found the following to work (at least fire, but it seemed to constantly fire):
Private Sub Application_Reminder(ByVal Item As Object)
Call Send_Email_Using_VBA
MsgBox ("Litigate!")
End Sub
这是在 ThisOutlookSession
对象模块中设置的.添加这个对你有什么帮助吗?
This was set up in the ThisOutlookSession
object module. Does adding this do anything for you?
这篇关于如何使 application.reminder 事件起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!