Let me start by saying I am completely new to VBA as of today so apologies in advance, I won't have any advanced understanding.
I managed to find a VBA code online, in order to help me create automated emails.
In essence, the below code is picking up the desired email addresses in cell B2, and the mail body is the contents of cell C2. And it is all kicked off if the value entered into A2 is more than 0.
But for the life of me, I cannot make this flexible so that it does not apply to row 2. I want this to happen for row 3 (email address from B3, mail content of C3 [which is personalised for names] if the value entered into A3 is more than 0), and then row 4, row 5 etc. Could someone help me please?
Dim xRg As Range
'Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("A2"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 0 Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = Range("C2")
On Error Resume Next
With xOutMail
.To = Range("B2")
.CC = ""
.BCC = ""
.Subject = "Engaging our Clients on Sustainability"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
I managed to find a VBA code online, in order to help me create automated emails.
In essence, the below code is picking up the desired email addresses in cell B2, and the mail body is the contents of cell C2. And it is all kicked off if the value entered into A2 is more than 0.
But for the life of me, I cannot make this flexible so that it does not apply to row 2. I want this to happen for row 3 (email address from B3, mail content of C3 [which is personalised for names] if the value entered into A3 is more than 0), and then row 4, row 5 etc. Could someone help me please?
Dim xRg As Range
'Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("A2"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 0 Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = Range("C2")
On Error Resume Next
With xOutMail
.To = Range("B2")
.CC = ""
.BCC = ""
.Subject = "Engaging our Clients on Sustainability"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub