给出以下功能,我希望将变量submitForm
替换为从Excel电子表格范围生成的表格,该表格也附加到电子邮件中。
%TABLE_HERE%
我做了一些研究,并发现了一个很棒的功能,可以为你做这一切,并希望与大家分享!请参阅下面的答案
答案 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