How to Fire Outlook VBA When Appt Reminder Opens

The attached code works without problem, but only fires when I log onto my system each day.  Even if I close my Outlook and re-open, the code will not fire.  I can log-off my PC and then when I log back on and open my Outlook, the code fires....but that's the only way that it works.  I need the action to fire when the appointment reminder opens.  Is this happening because we are using "Private Sub Application_Startup"?  Is there another option?  I tried changing this line to "Private Sub Application_Reminder(ByVal Item As Object)", but that didn't work either.  

As always I look forward to some expert advice on this matter.

very respectfully,
Public WithEvents objReminders As Outlook.Reminders, _
    WithEvents objCalendarItems As Outlook.Items


Private Sub Application_Startup()
    Dim objNS As NameSpace
    Set objNS = Application.GetNamespace("MAPI")
    Set objInboxItems = objNS.GetDefaultFolder(olFolderCalendar).Items
    Set objNS = Nothing
    Set objReminders = Application.Reminders
End Sub


Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Dim objShell As Object, _
        objAppointment As Object
    Dim RetVal
    Set objShell = CreateObject("Wscript.Shell")
    If ReminderObject.Item.Class = olAppointment Then
        Set objAppointment = ReminderObject.Item
        'Change the start interval on the next line as desired.  The interval is in minutes.
        If DateDiff("n", Now, objAppointment.Start) <= 2 Then
            If objAppointment.Categories = "LaunchAccess" Then
                RetVal = Shell("C:\Appointment_Reminder\RunTextMessage.bat")
            End If
        End If
    End If
    Set objAppointment = Nothing
    Set objShell = Nothing
End Sub

Open in new window

Who is Participating?
David LeeCommented:
Hi, gwflyer.

I tested the code and it is firing every time there's a reminder.  However, the code usually fails at the IF statement on line 24 or 25. Most of the time the code is firing outside of two minute before the appointment starts.  When I set an appointment to fire within that time frame the code then failed on the category test on line 25.  The simplest way to determine that the code is in fact firing each time a reminder fires is to add

    Debug.Print "Reminder Fired"

just after line 19 of the objReminders_ReminderFire subroutine.
gwflyerAuthor Commented:

Thank you very much for your help with this.  I did add "Debug.Print" to the code and you are right that it is firing.  I also focused on the lines that you mentioned in the code and found that setting it to "<2" was my problem because the lowest setting that I have for a reminder is "5 minutes"; so I've revised this to "<10" to be sure that it fires even if there is a couple minute delay.  It now works.  Thanks again for leading me to the right solution.  

David LeeCommented:
You're welcome, George!  Glad I could help out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.