VBA创建/发送OUTLOOK邮件时怎么加上默认签名呢?用过OUTLOOK写邮件的人都知道,如果你设置了默认签名,那么在创建空白邮件的时候就会自动加上你设置的签名。根据这一特性,我们可以在用VBA创建/发送OUTLOOK邮件的时候不设置HTMLBody属性,而是采用复制粘贴的方式将正文模板复制粘贴到新建的邮件中去。
原理就是先复制工作表的表格(含格式),然后插入到有正文内容的word文件的特定位置,再把word文件的所有内容全部复制到新建的OUTLOOK邮件。这种方法相比于使用HTMLBody属性,省时省力,适合不会写html代码的小白,值得一试。
这是附件
Sub EmailTest() Dim OutApp As Object Dim WordApp As Object Dim OutMail As Object Dim WordDoc As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) Set WordApp = CreateObject("Word.Application") Set WordDoc = WordApp.Documents.Open(Environ("userprofile") & "DesktopEmailTest est.docx") ThisWorkbook.Sheets(1).Range("a1").CurrentRegion.Copy WordDoc.Paragraphs(5).Range.PasteExcelTable linkedtoexcel:=False, Wordformatting:=False, RTF:=False WordDoc.Tables(1).AutoFitBehavior wdAutoFitWindow WordDoc.Content.Copy With OutMail .To = "XXXXXXXXX.com" .Importance = 2 .Subject = "Test Email" .Display End With OutApp.ActiveInspector.WordEditor.Application.Selection.Paste WordApp.Quit savechanges:=False Set OutApp = Nothing Set OutMail = Nothing Set WordDoc = Nothing Set WordApp = Nothing End Sub