首页 > 解决方案 > 如何添加 HTMLBody 签名?

问题描述

我需要在生成的 Outlook 电子邮件末尾添加我的签名。

我将我的 ( .HTMLBody = msg) 更改为 ( .HTMLBody = msg & .HTMLBody)。这让我的签名显示出来,但我的消息文本消失了。当我.HTMLBody在最后删除并使用我的原始代码时,我的文本显示格式正确但没有签名。

Sub Email()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim Path As String
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    msg = "<p>Hello World,</p><br>"

    On Error Resume Next
    With OutMail
        .Display
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "Fruits Stock " & Path
        .HTMLBody = msg & "Hello World" & .HTMLBody
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

标签: vbaoutlook

解决方案


你用谷歌搜索过MailItem.HTMLBody吗?

它在这里显示了一个示例:

Sub CreateHTMLMail() 
 
 'Creates a new email item and modifies its properties. 
 
 Dim objMail As Outlook.MailItem 
 
 
 
 'Create email item 
 
 Set objMail = Application.CreateItem(olMailItem) 
 
 With objMail 
 
 'Set body format to HTML 
 
 .BodyFormat = olFormatHTML 
 
 .HTMLBody = _ 
 
 "<HTML><BODY>Enter the message text here. </BODY></HTML>" 
 
 .Display 
 
 End With 
 
End Sub

如果您希望您的电子邮件采用 HTMl 格式,您需要设置一个标志:

.BodyFormat = olFormatHTML


查找MailItem.BodyFormat属性。


推荐阅读