How to Fire Outlook VBA When Appt Reminder Opens

Posted on 2011-04-28
Last Modified: 2013-12-23
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

Question by:gwflyer
    LVL 76

    Accepted Solution

    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.

    Author Closing Comment


    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.  

    LVL 76

    Expert Comment

    by:David Lee
    You're welcome, George!  Glad I could help out.

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
    Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
    The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
    The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now