On Error GoTo ErrorOut
Set olApp = CreateObject("Outlook.Application")
Set Wks = Worksheets("Sheet1")
Set Rng = Wks.Range("F4")
Set RngEnd = Wks.Cells(Wks.Rows.Count, Rng.Column).End(xlUp)
Set RngEnd = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd)
Set Rng = Wks.Range(Rng, RngEnd).Resize(Columnsize:=2)
Application.ScreenUpdating = False
For Each Cell In Rng
CellColor = xlColorIndexNone
With Cell.FormatConditions
Cell.Select
Condition1 = Evaluate(.Item(1).Formula1)
If Condition1 = True Then CellColor = .Item(1).Interior.ColorIndex
Condition2 = Evaluate(.Item(2).Formula1)
If Condition2 = True Then CellColor = .Item(2).Interior.ColorIndex
End With
'Yellow means due in 4 weeks. Comment is holds date time stamp for email.
If CellColor = 6 And (Cell.Comment Is Nothing) Then
SendTo = Wks.Cells(Cell.Row, "D").Text
Set olEmail = olApp.CreateItem(0)
With olEmail
.To = SendTo
.Subject = "Service Schedule"
.Body = "Email Test." 'Include your message between the quotes
.Send
Cell.AddComment "Email sent " & Now()
End With
End If
Next Cell
ErrorOut:
Application.ScreenUpdating = True
If Err <> 0 Then
MsgBox "ERROR - Emails Stopped" & vbCrLf & Err.Description & vbCrLf & SendTo
Err.Clear
On Error GoTo 0
End If
'Terminate the Outlook
olApp.Quit
'Free objects in memory
Set olApp = Nothing
Set olEmail = Nothing
End Sub
Bookmarks