stevethomas56
New Member
- Joined
- Dec 8, 2013
- Messages
- 10
Hi - I have written a macro to send an email (with attachment) to named recipients. It all works fine except that it won't copy the range of excel cells into the body of the email.
I have highlighted the part that is not working in bold below. The range "email_narrative" is the predefined excel range of data in the source workbook which I want to paste in the body of the email.
Any ideas why this is not working?
Sub emailsender()
Dim SplitsTo As String
Dim SplitsCC As String
Dim AllocationsTo As String
Dim AllocationsCC As String
Dim TempFileName As Variant
Dim Tempmessage As Variant
'Splits Distribution List
SplitsTo = Sheets("Checks").Range("email_to").Value
SplitsCC = Sheets("Checks").Range("email_cc").Value
TempFileName = Sheets("Checks").Range("email_subject").Value
Tempmessage = Sheets("Checks").Range("email_narrative").Value
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
On Error Resume Next
With OutlookMail
.To = SplitsTo
.Cc = SplitsCC
.Subject = TempFileName
.Body = Tempmessage
.Attachments.Add Application.ActiveWorkbook.FullName
.Display
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
I have highlighted the part that is not working in bold below. The range "email_narrative" is the predefined excel range of data in the source workbook which I want to paste in the body of the email.
Any ideas why this is not working?
Sub emailsender()
Dim SplitsTo As String
Dim SplitsCC As String
Dim AllocationsTo As String
Dim AllocationsCC As String
Dim TempFileName As Variant
Dim Tempmessage As Variant
'Splits Distribution List
SplitsTo = Sheets("Checks").Range("email_to").Value
SplitsCC = Sheets("Checks").Range("email_cc").Value
TempFileName = Sheets("Checks").Range("email_subject").Value
Tempmessage = Sheets("Checks").Range("email_narrative").Value
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
On Error Resume Next
With OutlookMail
.To = SplitsTo
.Cc = SplitsCC
.Subject = TempFileName
.Body = Tempmessage
.Attachments.Add Application.ActiveWorkbook.FullName
.Display
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub