将文本格式添加到excel生成的电子邮件中的特定文本

时间:2018-07-21 19:37:24

标签: excel vba

我正在使用excel vba在电子邮件正文中将某些文本设置为粗体

这是我的代码

xFirstName = Sheets("Sheet1").Range("C2")
xMembershipDate = Sheets("Sheet1").Range("G2")

On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)

xMailBody = "Hello " & xFirstName & vbNewLine & _
"Your membership has been verified last " & xMembershipDate & vbNewLine & _
"" & vbNewLine & _
"Thank you."

我想将xFirstName和xMembershipDate设置为在电子邮件正文中显示为粗体。任何帮助是极大的赞赏。谢谢。

1 个答案:

答案 0 :(得分:0)

您必须使用HTML标记。

    xFirstName = Sheets("Sheet1").Range("C2")
    xMembershipDate = Sheets("Sheet1").Range("G2")

    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)

    With xOutMail
        .HTMLBody = "<p>Hello <b>" & xFirstName & "</b></p>" & _
                    "<p>Your membership has been verified last <b>" & xMembershipDate & "</b></p>" & _
                    "" & vbNewLine & _
                    "<p>Thank you.</p>"
    End With