How to Use VBA to Automate Task Reminders in Excel?

Cule_cocacola

New member
Joined
Oct 23, 2024
Messages
1
Reaction score
0
Points
1
Excel Version(s)
2019
I'm managing several venture projects in Excel and need a VBA script to send task reminders based on due dates listed in a sheet. The goal is to automatically send an email reminder when a task is nearing its deadline. How can I achieve this in Excel using VBA?
 
Code:
Option Explicit

Sub eMail()
Dim lRow As Integer
Dim i As Integer
Dim toDate As Date
Dim toList As String
Dim eSubject As String
Dim eBody As String
Dim OutApp
Dim OutMail

With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
End With

Sheets(1).Select
lRow = Cells(Rows.Count, 4).End(xlUp).Row

For i = 2 To lRow
toDate = Replace(Cells(i, 13), ".", "/")
  If Left(Cells(i, 5), 4) <> "Mail" And toDate = Date Then '<= 1 is set to send email 1 days prior to the send date / SHEET 1
                                                                'Change the number as desired.
     Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)

        toList = Cells(i, 4)    'gets the recipient from col D
        eSubject = "Project " & Cells(i, 2) & " is due on " & Cells(i, 3)
        eBody = "Dear " & Cells(i, 1) & vbCrLf & vbCrLf & "Please update your project status."
        
        On Error Resume Next
        With OutMail
        .To = toList
        .CC = ""
        .BCC = ""
        .Subject = eSubject
        .Body = eBody
        .bodyformat = 1
        .Display   ' ********* Creates draft emails. Comment this out when you are ready
        '.Send     '********** UN-comment this when you  are ready to go live
        End With
 
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
 Cells(i, 5) = "Mail Sent " & Date + Time 'Marks the row as "email sent in Column A"
End If
Next i

ActiveWorkbook.Save

With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
End With
End Sub
 

Attachments

  • WORKS Email on Date 3.xlsm
    22.8 KB · Views: 0
Back
Top