VBA to add multiple cells in the body of an email

Twinkievizzio11

New Member
Joined
Apr 27, 2017
Messages
30
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I am trying to add Cell E5 in the body of the email below E4. I am new using VBA. This is what I have so far.

Sub CreateEmail()
Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With ActiveSheet
Set rngTo = .Range("E2")
Set rngSubject = .Range("E3")
Set rngBody = .Range("E4")
End With
With objMail
.To = rngTo.Value
.Subject = rngSubject.Value
.body = rngBody.Value
.Display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
U didn't ask a question or say what's not working? I suspect that U are using ranges for variables. Trial changing them to strings. Dave
ie.
Code:
Dim rngTo As String
 Dim rngSubject As String
 Dim rngBody As String
 Set objOutlook = CreateObject("Outlook.Application")
 Set objMail = objOutlook.CreateItem(0)
 With ActiveSheet
 rngTo = .Range("E2")
 rngSubject = .Range("E3")
 rngBody = .Range("E4")
 End With
 
Upvote 0
My questions is How do I add Cell E5 in a sheet called “email template” underneath the body of the email which is cell E4?
 
Upvote 0
In the body is different than below the body...
Code:
rngBody = .Range("E4") & " " &  .Range("E5")
'or in the body below  .Range("E4")
rngBody = .Range("E4") & VbCrlf &  .Range("E5")
HTH. Dave
 
Upvote 0
I would like Cell E5 in the body below .Range ("E4")


I tried the code below and it's still not working

Sub CreateEmail()
Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With ActiveSheet
Set rngTo = .Range("E2")
Set rngSubject = .Range("E3")
Set rngBody = .Range("E4") & vbCrLf & .Range("E5")
End With
With objMail
.To = rngTo.Value
.Subject = rngSubject.Value
.body = rngBody.Value
.Display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
End Sub
 
Upvote 0
How can I add cell E5 in the body of the email under E4?


I tried the suggestions but none have worked.

Thank you.
 
Upvote 0
Maybe..
Code:
.Range("E4") & vbNewLine & .Range("E5")
You can also set it as a range and then enter it as Html. Dave
 
Upvote 0

Forum statistics

Threads
1,215,344
Messages
6,124,407
Members
449,157
Latest member
mytux

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