Results 1 to 14 of 14

Thread: Use Timer in Outlook

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Although it really doesn't matter, I would use a task, not an appointment.

    I may have given you the wrong event. Here's how I would do it.

    Just run the StartRemindingMe procedure to begin the process.

    Private WithEvents myReminders As Outlook.Reminders
    Const taskSubject As String = "Trigger Task"
    Const amountOfTime As Long = 10
    
    Private Sub myReminders_BeforeReminderShow(Cancel As Boolean)
        Dim remind As Outlook.Reminder
        ' check to make sure we're working on the correct reminder
        Set remind = myReminders.Item(1)
        If remind.Caption = taskSubject Then
             MsgBox ("This is where I would place my custom code")
        End If
        ' cancel the reminder
        Cancel = True
    End Sub
    
    Private Sub myReminders_ReminderFire(ByVal ReminderObject As Reminder)
        Dim tsk As Outlook.TaskItem
        ' create task again
        Set tsk = Application.CreateItem(olTaskItem)
        With tsk
             .subject = taskSubject
             .StartDate = Format(Now, "mm/dd/yyyy")
             .ReminderSet = True
             .reminderTime = DateAdd("n", amountOfTime, Now)
             .Save
        End With
    End Sub
    
    Public Sub StartRemindingMe()
        Dim olApp As Outlook.Application
        Dim olNS As Outlook.NameSpace
        Dim tsk As Outlook.TaskItem
        Dim tasksFolder As Outlook.MAPIFolder
        Dim tasks As Outlook.Items
        Dim matchingTasks As Outlook.Items
        Dim i As Long
        Dim task As Outlook.TaskItem
        ' only start watching reminders when I say so
        Set olApp = Outlook.Application
        Set myReminders = olApp.Reminders
        ' delete any existing tasks
        Set olNS = olApp.GetNamespace("MAPI")
        Set tasksFolder = olNS.GetDefaultFolder(olFolderTasks)
        Set tasks = tasksFolder.Items
        Set matchingTasks = tasks.Restrict("[Subject] = '" & taskSubject & "'")
        For i = matchingTasks.Count To 1 Step -1
             Set task = matchingTasks.Item(i)
             If task.subject = taskSubject Then
                 With task
                     .MarkComplete
                     .Delete
                 End With
             End If
        Next i
        ' create initial task
        Set tsk = Application.CreateItem(olTaskItem)
        With tsk
             .subject = taskSubject
             .StartDate = Format(Now, "mm/dd/yyyy")
             .ReminderSet = True
             .reminderTime = DateAdd("n", amountOfTime, Now)
             .Save
        End With
    End Sub
    Last edited by Aussiebear; 03-10-2025 at 07:24 PM.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •