Hello Everyone!
I hope you are all healthy and safe!
I wrote a VBA so that Excel will send out email if the value in a cells range changes (days countdown). The VBA write-up works just fine! However, I need to take it a step further! Eventually, I would like my VBA to do the below additions:
1) Send the email to the email address included in the spreadsheet (next to the cells counting the days); and
2) Include the client's name into the email's body.
I looked online for a solution since my VBA write up skills are not that good yet, but my experience with MrExcel showed me that there are Excel Gurus here who can help!!
I am uploading below a sample sheet to assist on explaining what I am aiming to do, as well as the current VBA written up!
Currently:
Excel sends out email to specific recipients (refer to my write up below) when "CALENDAR DAYS" (Column L) reach 31.
Eventually:
Excel should
1) send out email when "CALENDAR DAYS" reach 31;
2) to the email addresses listed under "OFFICERS (EMAIL)" (Column K); and
3) include in the email's body (apart from the standard wording I wrote) the value of the cell under "CUSTOMER NAME" (Column C).
SAMPLE:
VBA Write up:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("L:L"), Target) Is Nothing Then
If IsNumeric(Target.Value) And Target.Value = 31 Then
Call Mail_small_Text_Outlook
End If
End If
End Sub
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Sub Mail_small_Text_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there," & vbNewLine & vbNewLine & _
"According to the information included in the Tracker designed by the Department, you have a client case approaching. Please check the Tracker for scheduling a coordination meeting." & vbNewLine & _
"Thank you in advance." & vbNewLine & _
"" & vbNewLine & _
"Kind regards," & vbNewLine & _
"The Department"
On Error Resume Next
With OutMail
.To = "samplemail1@test.net;samplemail2@test.net"
.CC = ""
.BCC = ""
.Subject = "AUTOMATED EMAIL SENT FROM EXCEL"
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Thank you in advance!
Kind regards,
Eraclis
I hope you are all healthy and safe!
I wrote a VBA so that Excel will send out email if the value in a cells range changes (days countdown). The VBA write-up works just fine! However, I need to take it a step further! Eventually, I would like my VBA to do the below additions:
1) Send the email to the email address included in the spreadsheet (next to the cells counting the days); and
2) Include the client's name into the email's body.
I looked online for a solution since my VBA write up skills are not that good yet, but my experience with MrExcel showed me that there are Excel Gurus here who can help!!
I am uploading below a sample sheet to assist on explaining what I am aiming to do, as well as the current VBA written up!
Currently:
Excel sends out email to specific recipients (refer to my write up below) when "CALENDAR DAYS" (Column L) reach 31.
Eventually:
Excel should
1) send out email when "CALENDAR DAYS" reach 31;
2) to the email addresses listed under "OFFICERS (EMAIL)" (Column K); and
3) include in the email's body (apart from the standard wording I wrote) the value of the cell under "CUSTOMER NAME" (Column C).
SAMPLE:
A | B | C | D | E | F | G | H | I | J | K | L |
CUSTOMER No. | CUSTOMER NAME | UNIT | ACTION No. | AREA | HEARING DATE (DD/MM/YYYY) | LAW FIRM | LM OFFICER | HANDLING OFFICERS | OFFICERS (EMAIL) | CALENDAR DAYS | |
1 | 12345678 | ABC | CORPORATE | 123 | Area 1 | 10/05/2021 | Lawyer 1 | LM Officer 1 | Officer 1 | Officer1@testmail.net | 12 |
2 | 12345679 | DEF | RETAIL | 456 | Area 2 | 10/07/2021 | Lawyer 2 | LM Officer 2 | Officer 2 | Officer2@testmail.net | 73 |
3 | 12345680 | GHI | RETAIL | 789 | Area 3 | 10/09/2021 | Lawyer 3 | LM Officer 3 | Officer 3 | Officer3@testmail.net | 135 |
4 | 12345681 | JKL | CORPORATE | 101 | Area 4 | 10/10/2021 | Lawyer 4 | LM Officer 4 | Officer 4 | Officer4@testmail.net | 165 |
5 | 12345682 | MNO | CORPORATE | 112 | Area 5 | 10/11/2021 | Lawyer 5 | LM Officer 5 | Officer 5 | Officer5@testmail.net | 196 |
6 | 12345683 | PQR | CORPORATE | 131 | Area 6 | 11/11/2021 | Lawyer 6 | LM Officer 6 | Officer 6 | Officer6@testmail.net | 197 |
7 | 12345684 | STU | CORPORATE | 415 | Area 7 | 11/12/2021 | Lawyer 7 | LM Officer 7 | Officer 7 | Officer7@testmail.net | 227 |
8 | 12345685 | VWX | CORPORATE | 161 | Area 8 | 11/01/2022 | Lawyer 8 | LM Officer 8 | Officer 8 | Officer8@testmail.net | 258 |
9 | 12345686 | YZA | RETAIL | 718 | Area 9 | 11/02/2022 | Lawyer 9 | LM Officer 9 | Officer 9 | Officer9@testmail.net | 289 |
10 | 12345687 | BCD | RETAIL | 192 | Area 10 | 12/03/2022 | Lawyer 10 | LM Officer 10 | Officer 10 | Officer10@testmail.net | 318 |
VBA Write up:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("L:L"), Target) Is Nothing Then
If IsNumeric(Target.Value) And Target.Value = 31 Then
Call Mail_small_Text_Outlook
End If
End If
End Sub
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Sub Mail_small_Text_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there," & vbNewLine & vbNewLine & _
"According to the information included in the Tracker designed by the Department, you have a client case approaching. Please check the Tracker for scheduling a coordination meeting." & vbNewLine & _
"Thank you in advance." & vbNewLine & _
"" & vbNewLine & _
"Kind regards," & vbNewLine & _
"The Department"
On Error Resume Next
With OutMail
.To = "samplemail1@test.net;samplemail2@test.net"
.CC = ""
.BCC = ""
.Subject = "AUTOMATED EMAIL SENT FROM EXCEL"
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Thank you in advance!
Kind regards,
Eraclis