I have a worksheet with given data,
I need to email the data using Microso
Here is the answer for that serves the purpose. The html body is build using string builder concept and the email is formed as required(Altered the sub of email from the post). This is working fine.
Public Function FormatEmail(Sourceworksheet As Worksheet, CoBDate As Date, FinalRatioLCR As Variant, FinalRatioAUD As Variant) Dim OutApp As Object Dim OutMail As Object Dim eMsg As String Dim ToRecipients As String On Error GoTo FormatEmail_Error Application.ScreenUpdating = False Set OutApp = CreateObject("Outlook.Application") Dim Matrix2_1, Matrix2_2, Matrix2_3, Matrix3_1 As String Dim FinanceAllCurrency, AllCurrencyT1, AllCurrencyT0, AllCurrencyAUD As Double 'FinanceAllCurrency = FinalRatioLCR AllCurrencyT1 = 10.12 AllCurrencyT0 = 20.154 'AllCurrencyAUD = FinalRatioAUD Matrix2_1 = "
" & FinalRatioLCR & " " Matrix2_2 = "" & AllCurrencyT1 & " " Matrix2_3 = "" & AllCurrencyT0 & " " Matrix3_1 = "" & FinalRatioAUD & " " eMsg = "" & _ "" ToRecipients = GetToRecipients Set OutMail = OutApp.CreateItem(0) With OutMail .To = ToRecipients .Subject = " Report -" & CoBDate .HTMLBody = "Hi All, " & "
" & _ " LCR Finance " & _ "Desk T+1 Desk T+0 " & _ " All Currency " & Matrix2_1 & Matrix2_2 & _ Matrix2_3 & _ "AUD Only " & Matrix3_1 & "- " & _ "-
" & _ eMsg .display End With On Error GoTo 0 Set OutMail = Nothing On Error GoTo 0 Exit Function FormatEmail_Error: Set OutApp = Nothing Application.ScreenUpdating = True MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure FormatEmail of Module modOutlook" End Function
Recipients adress is dynamically retrieved from a range.
Private Function GetToRecipients() As String Dim rngRows As Range Dim returnName As String For Each rngRows In shMapping.Range(MAPPING_EMAIL_RECIPIENTS).rows If Len(returnName) = 0 Then returnName = rngRows.Cells(, 2).value2 ElseIf Len(rngRows.Cells(, 2).value2) > 0 Or rngRows.Cells(, 2).value2 Like "?*@?*.?*" Then returnName = returnName & ";" & rngRows.Cells(, 2).value2 End If Next GetToRecipients = returnName End Function