I have code below to generate a reminder in Outlook Calendar, which generates a reminder to the microsoft outlook calendar
I need the code amended to check if the reminder is already in the calendar. If it is , then exit the sub or continue if not already in the calendar
Your assistance is most appreciated
I need the code amended to check if the reminder is already in the calendar. If it is , then exit the sub or continue if not already in the calendar
Your assistance is most appreciated
Code:
Sub SendReminderToOutlook()
Dim ws As Worksheet
Dim lastRow As Long
Dim olApp As Outlook.Application
Dim olApt As Outlook.AppointmentItem
Dim reportName As String
Dim dueDate As Date
' Set the worksheet containing data
Set ws = ThisWorkbook.Sheets("Reports Outstanding")
' Set Outlook Application
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If
' Find the last row with data in column A and D
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' Loop through the data and create reminders
For i = 2 To lastRow
reportName = ws.Cells(i, "A").Value
dueDate = ws.Cells(i, "D").Value
' Check if due date is in the future
If dueDate >= Date Then
' Create an appointment item for the due date
Set olApt = olApp.CreateItem(olAppointmentItem)
With olApt
.Start = dueDate
.End = dueDate
.AllDayEvent = True
.Subject = reportName
.Location = "None" ' Replace with appropriate location
.ReminderSet = True
.ReminderMinutesBeforeStart = 30 ' Adjust the reminder time (in minutes) as needed
.Body = "This is a reminder for the report: " & reportName
.Save
End With
End If
Next i
' Release Outlook objects
Set olApt = Nothing
Set olApp = Nothing
End Sub