Sub OutlookSendMail()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
ActiveWorkbook.SaveCopyAs Filename:=Environ("temp") & "\" & ThisWorkbook.Name
With OutMail
.Display
.Subject = "add subject here"
.Recipients.Add "Add your 1st Recipient@x.com"
.Recipients.Add "Add your 2nd Recipient@x.com"
.HTMLBody = RangetoHTML(ThisWorkbook.Sheets(1).Range("A1:O6")) & .HTMLBody
.Attachments.Add Environ("temp") & "\" & ThisWorkbook.Name
End With
Kill Environ("temp") & "\" & ThisWorkbook.Name
End Sub
Function RangetoHTML(Rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
Set TempWB = Workbooks.Add(1)
Rng.Copy
On Error Resume Next
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
.Rows("1:4").Insert Shift:=xlDown
.Cells(1, 1) = "Stuff to put in before you paste in the copy range"
.Cells(1, 1).Font.Bold
.Cells(2, 1) = "More lines before the table"
.Cells(3, 1) = "One more line before the table"
.DrawingObjects.Visible = True
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function