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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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