PDA

View Full Version : VBA onTime solution for Outlook



crimi
08-08-2010, 03:39 AM
Hi All,
for my business account I like to forward mails from a second mailbox in Outlook to my primary one.
Because of a lack of authorization (which I am not able to change) I can not setup a normal forward rule in the second mailbox.
So I need a VBA solution which automatically checks the second mailbox and forward new mails to my primary one.
This function should run every 5 minutes automatically. As there is no Application.onTime event in Outlookk, my idea is to create a task "VBAtimer".
The reminder of this task is after execution with my VBA code delayed by 5 minutes. So every 5 minutes the reminder starts, I execute my function and delay the reminder by 5 minutes.
This is working, but I don't like the reminder window popup for this special task "VBAtimer". At the moment the reminders are popping up and are highlighted, but the reminder "VBAtimer" is not in the list, because it was already delayed by VBA by 5 minutes.
Do you have any idea, how to prevent the reminder window from popping up and being highlighted? Or do you have another idea how to solve my problem in general?
This is my code:
Private Sub Application_Startup()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim objItems As Outlook.Items
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set objItems = myNamespace.GetDefaultFolder(olFolderTasks).Items
For Each objItem In objItems
If objItem.Subject = "VBAtimer" Then
objItem.StartDate = Now
objItem.ReminderSet = True
objItem.ReminderTime = DateAdd("n", 1, Now)
objItem.Save
End If
Next
End Sub
Private Sub Application_Reminder(ByVal Item As Object)
If Item.Subject = "VBAtimer" Then
Item.ReminderTime = DateAdd("n", 1, Now)
Item.ReminderSet = True
Item.Save
Debug.Print Now & " - execute Function"
End If
End Sub
Thanks a lot,
Patrick