.
Here is an example and sample workbook.
Option Explicit
Sub SendEmail()
Dim sCC As String, sSubj As String, sEmAdd As String
'// Change the values of these variables to suit
sEmAdd = Range("C1")
sCC = ""
sSubj = Range("C2")
With Application
.EnableEvents = 0
.ScreenUpdating = 0
.Calculation = xlCalculationManual
End With
On Error Resume Next
With CreateObject("Outlook.Application").CreateItem(0)
.To = sEmAdd
.CC = sCC
.Subject = sSubj
.HTMLBody = RangetoHTML(Sheets("To Csh Mgt").Range("c7:b33"))
'.Send '// Change this to .Display if you want to view the email before sending.
.display
End With
On Error GoTo 0
With Application
.EnableEvents = 1
.ScreenUpdating = 1
.Calculation = xlCalculationAutomatic
End With
End Sub
Function RangetoHTML(rng As Range)
Dim TempWB As Workbook, TempFile As String
TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteColumnWidths, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
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
With CreateObject("Scripting.FileSystemObject").GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = .readall
.Close
End With
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close 0
Kill TempFile
Set TempWB = Nothing
End Function
Bookmarks