Hi All,
I'm using some code from the net that sends an email if the due date is close but what I want it to do is if the name in column "F" is the same then send multiple lines in one email, if its different then send a separate email.
Is this possible?
This is the code that I'm using
I'm using some code from the net that sends an email if the due date is close but what I want it to do is if the name in column "F" is the same then send multiple lines in one email, if its different then send a separate email.
Is this possible?
This is the code that I'm using
VBA Code:
Dim Email As String, Subj As String
Dim Msg As String
Dim LastRow As Long, NextRow As Long, RowNo As Long
Dim wsEmail As Worksheet
Dim OutApp As Object
Dim OutMail As Object
Set wsEmail = ThisWorkbook.Sheets("SheetName")
With wsEmail
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For RowNo = 2 To LastRow
'Change "Date + 30" to suit your timescale
If .Cells(RowNo, "K") = "" And .Cells(RowNo, "E") <= Date + 7 Then
On Error Resume Next
Set OutApp = GetObject("Outlook.Application")
On Error GoTo 0
If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
Do: Loop Until Not OutApp Is Nothing
Set OutMail = OutApp.CreateItem(0)
With OutMail
Email = "User@email.com" 'Change to cell containing e-mail address
Subj = "Reminder for Destruction" 'Change to cell containing subject or type subject
'Msg = ""
Msg = "Hello" & "," & vbCrLf & vbCrLf _
& "This is an automated e-mail to let you know that box" & vbCrLf _
& wsEmail.Cells(RowNo, "A") & vbCrLf _
& "Is due for destruction on " & wsEmail.Cells(RowNo, "E") & vbCrLf _
& "Many Thanks, " & vbCrLf
.To = Email
.CC = ""
.SentOnBehalfOfName = "Your User Name" ' This is optional, you can delete this line.
.Subject = Subj
.ReadReceiptRequested = False
.Body = Msg
.Display
End With
Set OutApp = Nothing
Set OutMail = Nothing
.Cells(RowNo, "K") = "S"
.Cells(RowNo, "L") = "E-mail sent on: " & Now()
End If
Next
End With