Add Email Body Text - Excel/Outlook 2007

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,632
Office Version
  1. 365
Platform
  1. Windows
I have trhe following code to create an email, add a subject, body and attachment but the line to add the body text is causing an error
Code:
Set objMail = objOutlook.CreateItem(0)
      
With objMail
   .To = strEmail
   .Subject = Range("Admin_EmailSubject") & " - " & strMonth
   .Body = Range("Admin_EmailBody")
   .Attachments.Add ActiveWorkbook.Path & "\Client Outputs\" & strClient & " " & strMonth & ".pdf"
   .Send
End With
If I ignore the .Body line, the .Send executes with no problem.

Not entirely sure why this doesn't work as I can't find anything online other than what I have and this works in Excel 2016.

TIA
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You could try adding .Text to the body line as:

.Body = Range("Admin_EmailBody").Text
 
Upvote 0
What's the error?

How is the named range 'Admin_EmailBody' defined?
 
Upvote 0
Unsure of the error code as it was on my clients machine who uses Office 2007 and I don't get the error when I run via Excel 2007 but email via Outlook 2016. I will add the .Text and see if that fixes otherwise I will report back with the error code and description.

The text is defined as a Worksheet named range. I've never had an issue with referencing a named range before though.
 
Upvote 0
I think when you are inside a With Block referencing an email object you would need to qualify the worksheet the range is on.

Correction: The issue appears to be the added month detail. With that commented out - it works.
With the Worksheet added and the month detail added it works.

So maybe someone can explain that to me.....


Code:
Range("Admin_EmailSubject") '  & " - " & strMonth  - this works
Worksheets("Sheet1").Range("Admin_EmailSubject") & " - " & strMonth ' This works
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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