Vba 如何使application.reminder事件生效?

Vba 如何使application.reminder事件生效?,vba,events,outlook,Vba,Events,Outlook,我在一个类模块中有这段代码-如on和on所述 我尝试过使用的代码在底部的,这也不会启动 我能得到的只是outlook的提醒弹出窗口。没有断点被命中,Msgbox永远不会显示-即使我删除了函数调用。我已经重新启动了好几次,但都没有结果 我是否遗漏了一些重要内容?您正在使用with events处理对象上的提醒事件,但您没有声明要匹配的SUB。在我下面的代码中,请注意objReminders\u…与您的Application\u…subs 我在Outlook 2003中使用了您的代码(我没有Offi

我在一个类模块中有这段代码-如on和on所述

我尝试过使用的代码在底部的,这也不会启动

我能得到的只是outlook的提醒弹出窗口。没有断点被命中,Msgbox永远不会显示-即使我删除了函数调用。我已经重新启动了好几次,但都没有结果


我是否遗漏了一些重要内容?

您正在使用
with events
处理
对象上的
提醒
事件,但您没有声明要匹配的SUB。在我下面的代码中,请注意
objReminders\u…
与您的
Application\u…
subs

我在Outlook 2003中使用了您的代码(我没有Office 2007,因此无法在那里进行测试),并得出以下结论:

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
在普通代码模块中使用此功能实现:

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
事件上触发的,我显式地调用它。但是,这也可以在事件第一次出现时触发(据我所知,这不会在提醒从
睡眠中唤醒时触发)。我没有设置任何用于测试的提醒-如果您有超出此范围的困难,我将设置一些与此相关的我自己的测试

Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Call Send_Email_Using_VBA
    MsgBox ("Litigate!")
End Sub

更新:

在2010年玩过这个游戏后,我发现以下方法可行(至少是fire,但它似乎一直在燃烧):


这是在对象模块中设置的。添加它对您有帮助吗?

值得注意的是,它必须位于ThisOutlookSession代码中,而不是其他模块中

Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Call Send_Email_Using_VBA
    MsgBox ("Litigate!")
End Sub

这个问题的实际答案如下: 如果您正在设置定期约会,并将代码放入约会的应用程序提醒事件中,则除非您在约会本身的下拉列表中专门设置了提醒期限,否则不会触发提醒事件

我已经玩了好几天了,除非是一次约会,否则这项活动永远不会启动——重复性从未奏效

设置一个定期约会,提醒时间为5分钟,一切正常

仅供参考,这里有一些代码,我使用存储在本地文件夹中的电子邮件模板每月发送用户信息(自我密码重置)提醒。现在效果很好。请记住,如果发送的自动邮件被称为链接“发送邮件”,请创建自己的新类别。每个约会都必须设置为该类别,并在子类别中进行检查

    Private Sub Application_Reminder(ByVal Item As Object)
      Dim objMsg As MailItem

       On Error Resume Next


    'IPM.TaskItem to watch for Task Reminders
    If Item.MessageClass <> "IPM.Appointment" Then
      Exit Sub
    End If

    If Item.Categories <> "Send Mail" Then
      Exit Sub
    End If

     'Check which Template for Reminder we need to send by looking for the keyword in the Reminder Appointment

If InStr(Item.Subject, "e-Expenses Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\e-Expenses Resetting your own password.oft")

ElseIf InStr(Item.Subject, "e-Learning Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\e-Learning Resetting your own password.oft")

ElseIf InStr(Item.Subject, "EMIS Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\EMIS Web Resetting your own password.oft")

ElseIf InStr(Item.Subject, "NHS email Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\NHS Net eMail Resetting your own password.oft")

ElseIf InStr(Item.Subject, "STRATA Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\STRATA Resetting your own password.oft")

ElseIf InStr(Item.Subject, "VPN Password String Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\VPN Resetting your own password.oft")

Else: Exit Sub

End If

 'Location is the email address we send to, typically to ALL users
  objMsg.To = Item.Location
  objMsg.Subject = Item.Subject  'Make the subject of the Appointment what we want to say in the Subject of the email
  objMsg.Send


  Set objMsg = Nothing
End Sub
私有子应用程序\u提醒(ByVal项作为对象)
Dim objMsg作为邮件项
出错时继续下一步
'要监视任务提醒的IPM.TaskItem
如果Item.MessageClass为“IPM.Appointment”,则
出口接头
如果结束
如果项目类别为“发送邮件”,则
出口接头
如果结束
'通过在提醒约会中查找关键字,检查需要发送的提醒模板
如果InStr(Item.Subject,“电子费用密码重置”)>0,则
设置objMsg=Application.CreateItemFromTemplate(“C:\remention Emails\e-Expenses重置您自己的密码.oft”)
ElseIf InStr(Item.Subject,“电子学习密码重置”)>0然后
设置objMsg=Application.CreateItemFromTemplate(“C:\remention Emails\e-Learning重置您自己的密码.oft”)
ElseIf InStr(Item.Subject,“EMIS密码重置”)>0然后
设置objMsg=Application.CreateItemFromTemplate(“C:\rementer Emails\EMIS Web重置您自己的密码.oft”)
ElseIf InStr(Item.Subject,“NHS电子邮件密码重置”)>0然后
设置objMsg=Application.CreateItemFromTemplate(“C:\remention Emails\NHS Net eMail重置您自己的密码.oft”)
ElseIf InStr(Item.Subject,“地层密码重置”)>0然后
设置objMsg=Application.CreateItemFromTemplate(“C:\remention Emails\t重置您自己的密码.oft”)
ElseIf InStr(Item.Subject,“VPN密码字符串重置”)>0然后
设置objMsg=Application.CreateItemFromTemplate(“C:\remention Emails\VPN重置您自己的密码.oft”)
其他:退出子系统
如果结束
“Location是我们发送给的电子邮件地址,通常发送给所有用户
objMsg.To=项目位置
objMsg.Subject=Item.Subject'让约会主题成为我们想在电子邮件主题中说的内容
发送
设置objMsg=Nothing
端接头
玩得开心


Dave Thomas

可能也会有所帮助。我添加了
句柄objReminders.emminders
(然后尝试了
objReminders.Application.emminders
)它只是突出显示了
句柄
这个词,并告诉我“预期:语句结束”。您具体想做什么?你的目标是什么?没用。我测试了他们两个。(如果这有什么不同的话,使用2007)什么不起作用?是否存在错误(编译时或运行时)或静默运行?你有打盹的提醒吗?您是否将
Dim rmd更正为新的提醒类
,以匹配您自己的类名?Office版本可能会产生影响,但在快速搜索中,我没有发现任何确定的方法。在类模块中,一旦将事件objReminders声明为Outlook.Reminders后,您应该能够在代码窗口顶部的左侧下拉列表中选择
objReminders
。这样做,然后看看右边的选项。如果它们与我的代码不匹配,请使用您看到的。无错误。没有断点命中。修复了命名-我不知道它是指我的类。但它仍然不起作用。在类模块和普通模块中都测试了test()函数。很抱歉,我无法在我的计算机上复制(同样,2003年不是2007年),因此我不确定是什么原因导致此功能无法工作。即使没有触发事件处理,
Snooze
操作是否至少起作用?不,没有。(很抱歉耽搁了,我在假期前的最后一天发布了这个问题,目前有一个更大的问题要解决)
Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Call Send_Email_Using_VBA
    MsgBox ("Litigate!")
End Sub
    Private Sub Application_Reminder(ByVal Item As Object)
      Dim objMsg As MailItem

       On Error Resume Next


    'IPM.TaskItem to watch for Task Reminders
    If Item.MessageClass <> "IPM.Appointment" Then
      Exit Sub
    End If

    If Item.Categories <> "Send Mail" Then
      Exit Sub
    End If

     'Check which Template for Reminder we need to send by looking for the keyword in the Reminder Appointment

If InStr(Item.Subject, "e-Expenses Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\e-Expenses Resetting your own password.oft")

ElseIf InStr(Item.Subject, "e-Learning Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\e-Learning Resetting your own password.oft")

ElseIf InStr(Item.Subject, "EMIS Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\EMIS Web Resetting your own password.oft")

ElseIf InStr(Item.Subject, "NHS email Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\NHS Net eMail Resetting your own password.oft")

ElseIf InStr(Item.Subject, "STRATA Password Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\STRATA Resetting your own password.oft")

ElseIf InStr(Item.Subject, "VPN Password String Resets") > 0 Then
    Set objMsg = Application.CreateItemFromTemplate("C:\Reminder Emails\VPN Resetting your own password.oft")

Else: Exit Sub

End If

 'Location is the email address we send to, typically to ALL users
  objMsg.To = Item.Location
  objMsg.Subject = Item.Subject  'Make the subject of the Appointment what we want to say in the Subject of the email
  objMsg.Send


  Set objMsg = Nothing
End Sub