Add Email Body Text - Excel/Outlook 2007

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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