2

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.

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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Citrus Rain
  • 119
  • 1
  • 4
  • 16
  • 1
    [This related link from MSDN](http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/ea119a5f-cdff-4c00-8c50-826a0630c8bb/) might also help. – Gaffi Jul 18 '12 at 16:01
  • I added `handles objReminders.Reminders` (then tried `objReminders.Application.Reminders`) It just highlights the word `handles` and tells me "Expected: End of Statement." – Citrus Rain Jul 18 '12 at 16:47
  • What specifically are you trying to do? What is your goal? – JimmyPena Jul 22 '12 at 17:33

3 Answers3

2

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.

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

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

Update:

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

This was set up in the ThisOutlookSession object module. Does adding this do anything for you?

Gaffi
  • 4,307
  • 8
  • 43
  • 73
  • It didn't work. I tested both of them. (Using 2007 if that makes any difference) – Citrus Rain Jul 18 '12 at 18:14
  • What did not work? Was there an error (compile- or run-time), or a silent run? Did you have reminders to be able to snooze? Did you correct `Dim rmd As New ReminderClass` to match your own class name? The Office version *may* have an impact, but in a quick search I found nothing definitive either way. In your class module, once you have declared `Public WithEvents objReminders As Outlook.Reminders`, you should be able to select `objReminders` in the left drop-down at the top of the code window. Do that, then look at the options on the right. If they do not match my code, use what you see. – Gaffi Jul 18 '12 at 18:50
  • No errors. No breakpoints hit. Fixed the naming - didn't realize it was referring to the class I had. But it's still not working. Tested having the test() function in both the class module and a normal module. – Citrus Rain Jul 18 '12 at 19:04
  • I'm sorry, I can't reproduce on my machine (again, 2003 not 2007), so I'm not sure what else might be causing this to not work. Did the `Snooze` action work at least, even if it did not trigger the event handling? – Gaffi Jul 19 '12 at 17:25
  • No, it did not. _(sorry for the delay, I posted this question on the last day before vacation, and currently have a bigger issue to fix)_ – Citrus Rain Jul 30 '12 at 13:34
  • It did nothing. Is it possible my workplace has these disabled? – Citrus Rain Jul 30 '12 at 17:32
  • I suppose it is possible. I was prompted myself to enable macros (and had to in order to get this to work in 2010), but I was able to do this easily. Are you able to manually step through a test sub using ``? If so, I don't think this is the problem. – Gaffi Jul 30 '12 at 17:36
  • I mean the events. Macros run fine when I initiate them myself. – Citrus Rain Jul 30 '12 at 17:38
  • I particularly like the update to the answer, which explains that the code snippet can go in the ThisOutlookSession module. (In my VBA IDE for Outlook, this means under Project1 > Microsoft Outlook Objects > ThisOutlookSession. That's what I tested, and it works as described.) – Spacewaster Oct 08 '14 at 14:25
1

It's worth noting that this must be in the ThisOutlookSession code, not a different module

Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Call Send_Email_Using_VBA
    MsgBox ("Litigate!")
End Sub
bummi
  • 27,123
  • 14
  • 62
  • 101
David Bollman
  • 133
  • 1
  • 5
0

The actual ANSWER to this question is the following: If you are setting recurring appointments, and putting code in the Application_Reminder event on an appointment, the Reminder event will NOT fire unless you specifically set a Reminder period in the drop down within the Appointment itself.

I played with this for days, the event would never fire unless it was a single Appointment - recurring never worked.

Setting a recurring appointment with a Reminder time of 5 minutes and all is working perfectly.

FYI here is some code that I use to send user information (self password reset) reminders on a monthly basis, using email templates stored in a local folder. Works perfectly now. Remember to create your own new category if sending auto-emails called something linke 'Send Mail'. Each appointment must be set to this category and is checked within the 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

Have fun.

Dave Thomas

Sampada
  • 2,931
  • 7
  • 27
  • 39