Excel范围已添加到电子邮件模板

时间:2017-10-24 19:12:39

标签: excel vba excel-vba

给出以下功能,我希望将变量submitForm替换为从Excel电子表格范围生成的表格,该表格也附加到电子邮件中。

%TABLE_HERE%

我做了一些研究,并发现了一个很棒的功能,可以为你做这一切,并希望与大家分享!请参阅下面的答案

1 个答案:

答案 0 :(得分:1)

Public Function GenerateEmail(fileName As String, tbleRange As Range)

    Application.ScreenUpdating = False

    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItemFromTemplate(fileName)

    With OutMail
        .HTMLbody = Replace(OutMail.HTMLbody, "%TABLE_HERE%", RangetoHTML(tbleRange))
        .Attachments.Add (Application.ActiveWorkbook.FullName)
        .Display
    End With

    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Function

Website I got it from here...