I am stuck.
I am trying to create a macro that will copy an excel range into the body of an email. I would prefer to use HTML to retain the formatting.
Range is C5:E5 xldown
I can send the email with the workbook as an attachement (which I want), I just can't seem to get the range in the body.
The below version sent the email and attachement, but "-1" as the message body. Definitely now what I had wanted! I have left in my commented out lines that I used as I was trying to figure things out in case I was close with them.
I am trying to create a macro that will copy an excel range into the body of an email. I would prefer to use HTML to retain the formatting.
Range is C5:E5 xldown
I can send the email with the workbook as an attachement (which I want), I just can't seem to get the range in the body.
The below version sent the email and attachement, but "-1" as the message body. Definitely now what I had wanted! I have left in my commented out lines that I used as I was trying to figure things out in case I was close with them.
Code:
Sub Email()
Dim dataRange As Excel.Range
'xlWorkSheet = Sheets("Total Hours by Manager").Select
Sheets("Total Hours by Manager").Select
dataRange = Range("C5:E5").End(xlDown).Select
'Range(Selection, Selection.End(xlDown)).Select
Set otlApp = CreateObject("Outlook.Application")
Set otlNewMail = otlApp.CreateItem(olMailItem)
FName = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
Dim myOutlok As Object
Dim myMailItm As Object
Set otlApp = CreateObject("Outlook.Application")
Set otlNewMail = otlApp.CreateItem(olMailItem)
FName = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
With otlNewMail
.To = [EMAIL]xxxxx@xxxxx.com[/EMAIL]
.Body = "Attached is this pay period's Report." & Chr(13)
.Attachments.Add FName
.Send
End With
Set otlNewMail = Nothing
Set otlApp = Nothing
Set otlAttach = Nothing
Set otlMess = Nothing
Set otlNSpace = Nothing
End Sub