mattmcclements
New Member
- Joined
- Apr 15, 2022
- Messages
- 36
- Office Version
- 2016
- Platform
- Windows
Hi,
I want to add a variable into the body of text to say, you have an investigation to complete on "x" but I'm unsure how to do so. The information is stored in A. This is the code I have so far, I'm still at very early stages of VBA so any help would be greatly appreciated.
Thank you
Dim Xrg As Range
'Update by Extendoffice 2020/7/17
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MailAddress As String
Dim MailAddress_CC As String
On Error Resume Next
If Intersect(Range("E2:ZZ1000"), Target) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
If IsNumeric(Target.Value) Then
If Target.Value >= 3 Then
MailAddress = Range("S" & Target.Row).Value
MailAddress_CC = Range("T" & Target.Row).Value
Call Mail_small_Text_Outlook(MailAddress, MailAddress_CC)
' Send the email
emailItem.Send
End If
End If
End Sub
Sub Mail_small_Text_Outlook(MailAddress As String, MailAddress_CC As String)
Dim xOutApp As Object
Dim xOutMail As Object
Dim cell As Range
Dim strbody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
On Error Resume Next
With xOutMail
.To = MailAddress
.Cc = MailAddress_CC
.BCC = ""
.subject = "Driver Errors Investigation"
.htmlBody = "Hi," & vbNewLine & vbNewLine & "You have driver error investigations to complete on" & Cells(cell.Row, "A").Value & ""
.Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
I want to add a variable into the body of text to say, you have an investigation to complete on "x" but I'm unsure how to do so. The information is stored in A. This is the code I have so far, I'm still at very early stages of VBA so any help would be greatly appreciated.
Thank you
Dim Xrg As Range
'Update by Extendoffice 2020/7/17
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MailAddress As String
Dim MailAddress_CC As String
On Error Resume Next
If Intersect(Range("E2:ZZ1000"), Target) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
If IsNumeric(Target.Value) Then
If Target.Value >= 3 Then
MailAddress = Range("S" & Target.Row).Value
MailAddress_CC = Range("T" & Target.Row).Value
Call Mail_small_Text_Outlook(MailAddress, MailAddress_CC)
' Send the email
emailItem.Send
End If
End If
End Sub
Sub Mail_small_Text_Outlook(MailAddress As String, MailAddress_CC As String)
Dim xOutApp As Object
Dim xOutMail As Object
Dim cell As Range
Dim strbody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
On Error Resume Next
With xOutMail
.To = MailAddress
.Cc = MailAddress_CC
.BCC = ""
.subject = "Driver Errors Investigation"
.htmlBody = "Hi," & vbNewLine & vbNewLine & "You have driver error investigations to complete on" & Cells(cell.Row, "A").Value & ""
.Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub