Sub Paste_Excel_Range_To_Mail_Body()
Dim rng As Range
Dim Wb As Workbook
Application.ScreenUpdating = False
'
Ensure range is selected before it gets copied
Selection.Copy
Set rng = Selection
Path = Environ("Userprofile") & "\Desktop\tem.html"
Set Wb = Workbooks.Add
ActiveCell.PasteSpecial xlPasteValues
ActiveCell.PasteSpecial xlPasteFormats
ActiveCell.PasteSpecial xlPasteColumnWidths
Wb.PublishObjects.Add(xlSourceRange, Path, Wb.Sheets(1).Name, Wb.Sheets(1).UsedRange.Address, xlHtmlStatic).Publish (True)
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim final_file As Scripting.TextStream
Set final_file = fs
penTextFile(Path, ForReading)
Dim readme As Variant
readme = final_file.ReadAll
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Dear XXX," & vbNewLine & vbNewLine & _
"Please find below the details.<br>" & "<table align = left >" & readme & "</table>" & "<br>"
On Error Resume Next
With OutMail
.Display
.body = ""
.HTMLBody = strbody & .HTMLBody
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
final_file.Close
Kill Path
Application.ScreenUpdating = True
End Sub