Hi there,
See if the following code does what you need:
Option Explicit
Sub TestSend()
Const sCOLUMN__SEND_REMINDER As String = "J"
Const sCOLUMN__REMINDER_SENT As String = "L"
Const sCOLUMN__REMINDER_DATE As String = "M"
Const sCOLUMN__CONTACT_NAME As String = "G"
Const sCOLUMN__CONTRACT_NO As String = "C"
Const sCOLUMN__EXPIRY_DATE As String = "D"
Const sCOLUMN__ADDRESS As String = "K"
Const iMAXIMUM_NO_OF_ROWS As Integer = 100
Const iFIRST_ROW_NO As Integer = 4
Const sSHEET_NAME As String = "Sheet1"
Const iMAIL_ITEM As Integer = 1
Dim objMailItem As Object
Dim objOutlook As Object
Dim sSubject As String
Dim iRowNo As Integer
Dim sBody As String
Dim sTo As String
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(sSHEET_NAME)
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Session.Logon
For iRowNo = iFIRST_ROW_NO To (iFIRST_ROW_NO + iMAXIMUM_NO_OF_ROWS - 1)
With wks
If .Range(sCOLUMN__CONTRACT_NO & iRowNo).Value <> vbNullString Then
If .Range(sCOLUMN__EXPIRY_DATE & iRowNo) - 14 < Date Then
If .Range(sCOLUMN__SEND_REMINDER & iRowNo) = "Send Reminder" And _
.Range(sCOLUMN__REMINDER_SENT & iRowNo) = vbNullString Then
sTo = .Range(sCOLUMN__ADDRESS & iRowNo).Value
sSubject = "Contract " & .Range(sCOLUMN__CONTRACT_NO & iRowNo).Value & _
" is expiring on " & .Range(sCOLUMN__EXPIRY_DATE & iRowNo).Value
sBody = "Dear " & .Range(sCOLUMN__CONTACT_NAME & iRowNo).Value & _
vbNewLine & _
"Please update me on this contract's status"
Set objMailItem = objOutlook.CreateItem(iMAIL_ITEM)
With objMailItem
.To = sTo
.Subject = sSubject
.Body = sBody
.Display
End With
.Range(sCOLUMN__REMINDER_DATE & iRowNo) = "Mail Sent " & Now()
.Range(sCOLUMN__REMINDER_SENT & iRowNo) = "Reminder Sent"
End If
End If
End If
End With
Next iRowNo
Set objMailItem = Nothing
Set objOutlook = Nothing
Set wks = Nothing
End Sub
The highlighted values can be changed to suit your own requirements. Specifying the various column letters as constants at the start of the routine makes life a bit easier if the layout of your worksheet ever changes.
I would suggest combining the "Reminder Sent" and "Reminder Date" cells into a single cell containing "Reminder Sent" plus the date.
Hope this help - please let me know how you get on.
Regards,
Greg M
Bookmarks