I am trying to modify this code to send variations of the msg, but it seems it is either/or and won't recognize the If-Then-Else statement I put in. My data has Names, Report Name, Due Dates. If the report is not overdue (Days > 0) I want to send one message and if it is overdue (Days <0) I want to send a difference email. I appreciate any assistance.
Option Explicit
Sub SendEmail()
'Uses late binding
Dim OutlookApp As Object
Dim MItem As Object
Dim cell As Range
Dim Subj As String
Dim EmailAddr As String
Dim Recipient As String
Dim Msg As String
Dim Document As String
Dim Days As String
'Create Outlook object
Set OutlookApp = CreateObject("Outlook.Application")
'Loop through the rows
For Each cell In Columns("D").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" Then
'Get the data
Subj = "Compliance Reminder"
Recipient = cell.Offset(0, -3).Value
EmailAddr = cell.Value
Document = cell.Offset(0, -1).Value
Days = cell.Offset(0, 2).Value
'Compose message
If Days > 0 Then
Msg = Recipient & vbCrLf & vbCrLf
Msg = Msg & "This is a reminder that the "
Msg = Msg & Document
Msg = Msg & " is overdue due in "
Msg = Msg & Days
Msg = Msg & " days."
Else
Msg = Recipient & vbCrLf & vbCrLf
Msg = "Holy Crap, you did it!"
'Create Mail Item and send it
Set MItem = OutlookApp.CreateItem(0) 'olMailItem
With MItem
.to = EmailAddr
.Subject = Subj
.Body = Msg
'.Send
.Save 'to Drafts folder
End With
End If
End If
Next
Set OutlookApp = Nothing
End Sub
[/CODE]
Bookmarks