0

I know the following link exists. Though I've spend a significant amount of time researching, I've come up oddly empty handed. https://support.office.com/en-sg/article/Manage-email-messages-by-using-rules-c24f5dea-9465-4df4-ad17-a50704d66c59

I know you can tell it to run a script in the rules wizard, but the events which would trigger it are not what I need. Is there a template I can DL or create that will allow me to use outlook to kick of a script at specific times? I do not want to use Windows Task Scheduler for this process. Additionally, I would deeply prefer methods that do not require an email trigger--because the script in question will be checking for the existence of emails fitting criteria. Perhaps there is a means of using the outlook Tasks (recurring) to act as a trigger--but I have yet to find it.

Any and all help would be appreciated.

Archaimot
  • 93
  • 12

1 Answers1

0

You can use a timer in VBA to get your code running periodycally (for example, every N hours). Take a look at the Outlook VBA - Run a code every half an hour similar thread for more information and sample code.

Also you may find the page helpful.

Place the following code in the ThisOutlookSession module (Tools->Macros->VB Editor):

Private Sub Application_Quit()
  If TimerID <> 0 Then Call DeactivateTimer 'Turn off timer upon quitting **VERY IMPORTANT**
End Sub

Private Sub Application_Startup()
  MsgBox "Activating the Timer."
  Call ActivateTimer(1) 'Set timer to go off every 1 minute
End Sub

Place the following code in an new VBA module

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)
  MsgBox "The TriggerTimer function has been automatically called!"
End Sub
Community
  • 1
  • 1
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45