Sphinxy1542
New Member
I am using the code below to populate an email when a task is 30 days or less away. This should populate upon opening excel.
It initially worked, but was pulling up all dates regardless of when they were.
I have added in the below, but it's now not working at all. Would be very grateful for some assistance.
And
Full Code below, but workbook also attached.
It initially worked, but was pulling up all dates regardless of when they were.
I have added in the below, but it's now not working at all. Would be very grateful for some assistance.
Dim rowDate As Long, today As Long
And
today = Date
rowDate = xRgDate.Offset(I - 1).Value
If rowDate - today <= 30 And rowDate - today > 0 Then
Full Code below, but workbook also attached.
Private Sub Workbook_Open()
Dim xRgDate As Range
Dim xRgSend As Range
Dim xRgText As Range
Dim xRgDone As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xLastRow As Long
Dim vbCrLf As String
Dim xMailBody As String
Dim xRgDateVal As String
Dim xRgSendVal As String
Dim xMailSubject As String
Dim rowDate As Long, today As Long
Dim I As Long
On Error Resume Next
Set xRgDate = Range("A1:A2", Range("A" & Rows.Count).End(xlUp)) ' Email Address
xLastRow = xRgDate.Rows.Count
Set xRgDate = xRgDate(1)
Set xRgSend = Cells(xRgDate.Row, "B") ' Reminder Content
Set xRgText = Cells(xRgDate.Row, "C") ' Completion Deadline Date
Set xOutApp = CreateObject("Outlook.Application")
For I = 1 To xLastRow
xRgDateVal = xRgDate.Offset(I - 1).Value
today = Date
rowDate = xRgDate.Offset(I - 1).Value
If rowDate - today <= 30 And rowDate - today > 0 Then
xRgSendVal = xRgSend.Offset(I - 1).Value
xMailSubject = xRgText.Offset(I - 1).Value & " on " & xRgDateVal
vbCrLf = "<br><br>"
xMailBody = "<HTML><BODY>"
xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf ' Greeting
xMailBody = xMailBody & "Text : " & xRgText.Offset(I - 1).Value & vbCrLf
xMailBody = xMailBody & "</BODY></HTML>"
Set xMailItem = xOutApp.CreateItem(0)
With xMailItem
.Subject = xMailSubject
.To = xRgSendVal
.HTMLBody = xMailBody
.Display
'.Send
End With
Set xMailItem = Nothing
End If
Next
Set xOutApp = Nothing
End Sub