.
Here are two examples you can review and edit to your needs :
30 days out :
Option Explicit
Sub chkdate()
Dim n As String
Dim Today As Long
n = Sheets("Sheet1").Range("A1").Value
If n < (Now() + 30) Then
'MsgBox "Time !"
Send_Mail_From_Excel
End If
End Sub
Sub Send_Mail_From_Excel()
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
'Send Mass Email Using Excel VBA Macro Code
With OutlookMail
.to = "youremail@some.com"
.CC = ""
.BCC = ""
.Subject = "30 Day Check"
.Body = "Time to check the date !"
'.Send ' or just put .Send to directly send the mail instead of display
.Display
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
X Days Ahead :
Option Explicit
Sub SndMail()
Dim cll As Variant
Dim duedays As String
With Sheets("Sheet2")
For Each cll In .Range("G6:G" & .Cells(.Rows.Count, 7).End(xlUp).Row)
If cll.Value = Date + 30 And cll.Offset(, 7) = vbNullString Then
cll.Offset(, 7).Value = "X": duedays = 30
GoTo sendmail
ElseIf cll.Value = Date + 15 And cll.Offset(, 8) = vbNullString Then
cll.Offset(, 8).Value = "X": duedays = 15
GoTo sendmail
Else
GoTo continue
End If
sendmail:
With CreateObject("Outlook.Application").CreateItem(0)
.To = cll.Offset(, 1).Value
.Subject = "Risk Assessments Due"
.Body = "Dear, " & vbNewLine & vbNewLine & _
cll.Offset(, -6).Value & " is due in " & duedays & " days." & vbNewLine & vbNewLine & _
"Please contact us to make an appointment." & vbNewLine & vbNewLine & _
"Service Agent : " & cll.Offset(, 2).Value
'.Attachments.Add ("C:\test.txt")
.Display '.Send
End With
continue:
Next
End With
End Sub
Bookmarks