Formatting email body from Excel contents

前端 未结 2 1543
不知归路
不知归路 2021-01-14 08:41

I have a worksheet with given data,
\"enter

I need to email the data using Microso

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-14 09:15

    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 = "" & _
            "" & _
            "" & _
             "" & _
            "" & Matrix2_1 & Matrix2_2 & _
             Matrix2_3 & _
            "" & Matrix3_1 & "" & _
            "
    LCRFinanceDesk T+1Desk T+0
    All Currency
    AUD Only-     -  
    " ToRecipients = GetToRecipients Set OutMail = OutApp.CreateItem(0) With OutMail .To = ToRecipients .Subject = " Report -" & CoBDate .HTMLBody = "Hi All, " & "







    " & _ 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
    

提交回复
热议问题