I would like to ask you for a favour. I got a spreadsheet with code that sends an email if the cell (I3) contains a txt "YES".
Basically, if cell (J3) is empty then (I3) return the value "YES", then the code sends an email to addresses in cell (B3) once it's done it, the date appears to the cell (J3) and the value in (I3) changes to "NO". So on the next occasion the code knows that no emails needs to be send to to particular person.
I got this code of the internet. Done a little modification to the code to suit the sheet1. I'm very new to this, please be patient with me.
In cell (C3) I have the start date, cell (H3) the finish/due date. I would like my spreadsheet to send emails automatically without me opening the workbook. I would like a time trigger that would send emails if particular task is due in 30 days and if an email could be generated each monday until it reaches 0 days and then one email for overdue - 5.
Not sure if the cell (I3) or (J3) could be still in use.
I hope I explained everything clearly.
Dim uRange
Dim lRange
Dim BCell As Range
Dim iBody As String
Dim iTo As String
Dim iSubject As String
Dim DaysOverdue
Public Sub SetEmailParams()
Set uRange = Sheet1.Range("I2")
Set lRange = Sheet1.Range("I" & Rows.Count).End(xlUp)
iBody = Empty
iSubject = Empty
iTo = Empty
For Each BCell In Range(uRange, lRange)
If BCell.Value = "YES" Then
If DateDiff("d", Format(Now(), "dd/mm/yyyy"), Format(Range("G3"),
"dd/mm/yyyy")) <= 0 Then
DaysOverdue = DateDiff("d", Format(BCell.Offset(0, -6)),
Format(BCell.Offset(0, -1)))
iTo = BCell.Offset(0, -7).Value
iSubject = "Reminder"
iBody = "The job assigned to you under this describtion - " &
BCell.Offset(0, -4) & " in the name of " & BCell.Offset(0, -3) & " for the
confirmation date of " & BCell.Offset(0, -1) & " is due " & DaysOverdue & "
days."
SendEmail
BCell.Offset(0, 1).Value = Now()
End If
End If
Next BCell
End Sub
Private Sub SendEmail()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = iTo
.CC = ""
.BCC = ""
.Subject = iSubject
.Body = iBody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Send to automatically send without displaying
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub