Adding excel cell value to mail body in vba

Barbra090910

New Member
Joined
Jul 16, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have the following lookup data that i need to display in an email.
1594891900865.png


My code (below) works, but does not display the actual words in the cells on the email.

What am i missing?


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 = "Good day," & vbNewLine & vbNewLine & _
"Upon completion of the Buckman COVID-19 checklist, B2 has indicated that he/she might be at risk of having COVID-19." & vbNewLine & _
"The following response was generated based on their Health assessment feedback:" & vbNewLine & _
"D2" & vbNewLine & _
"Please address this matter with the above-mentioned employee urgently!" & vbNewLine & _
"Kind Regards," & vbNewLine & _
"COVID-19 Monitoring Team"

On Error Resume Next
With xOutMail
.To = "bmetsebeth@buckman.com"
.Subject = "Employee Health Alert - C2 "
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

This is the email i get.

1594891990392.png
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Check something like this.
Best regards .
VBA Code:
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 = "Good day," & vbNewLine & vbNewLine & _
    "Upon completion of the Buckman COVID-19 checklist, " & [B2] & " has indicated that he/she might be at risk of having COVID-19." & vbNewLine & _
    "The following response was generated based on their Health assessment feedback:" & vbNewLine & _
            [D2] & vbNewLine & "" _
    & "Please address this matter with the above-mentioned employee urgently!" & vbNewLine & _
    "Kind Regards," & vbNewLine & _
    "COVID-19 Monitoring Team"
    
    On Error Resume Next
    With xOutMail
    .To = "bmetsebeth@buckman.com"
    .Subject = "Employee Health Alert - C2 "
    .Body = xMailBody
    .Display 'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub
 
Upvote 0
Thank you.

Will this thread send out emails automatically if the cell value changes, even if excel is closed?
 
Upvote 0
If Excel is closed then "Worksheet_Change" does not work.
Best regards.
 
Upvote 0

Forum statistics

Threads
1,215,762
Messages
6,126,740
Members
449,335
Latest member
Tanne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top