I want to create a timer function for a macro to run in Outlook.


I want a timer to run my Overdue macro every minute to check if this is still the same; so if it has been more than 4 hours then the column should be updated from No to Yes.


I have found the below code. This runs every 1 minute as the code intended to, i have made a link to my macro by


Call Overdue
before the
End If
at the end of the code


Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long


Public TimerID As Long 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is running


Public Sub ActivateTimer(ByVal nMinutes As Long)
  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes
  If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer
  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)
  If TimerID = 0 Then
    MsgBox "The timer failed to activate."
  End If
End Sub


Public Sub DeactivateTimer()
Dim lSuccess As Long
  lSuccess = KillTimer(0, TimerID)
  If lSuccess = 0 Then
    MsgBox "The timer failed to deactivate."
  Else
    TimerID = 0
  End If
End Sub


Public Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)
    'keeps calling every X Minutes unless deactivated
    If idevent = TimerID Then
       ' MsgBox "The TriggerTimer function has been automatically called!"
         Call Overdue 
    End If
End Sub
When I run this code, I receive an error message: Compile Error, Sub or Function Not Defined for the Call Overdue line & also my Outlook crashes... I tried the code with
Declare PtrSafe Function
as well, but the same error occurs with this. Can anyone help? :)