在Outlook中

时间:2016-01-21 03:00:30

标签: vba outlook outlook-vba

我需要格式化从Outlook中的Excel获取的特定字符串值。

一旦Excel提供了值,宏就会在电子邮件中附加该值。

我尝试测试并将值设置为BOLD,但邮件的所有内容都变为BOLD。如何以我喜欢的方式使用字体类型,大小和颜色来格式化值?

obj.HTMLBody = "<b>" & StrAgnt & vbCrLf & obj.HTMLBody

1 个答案:

答案 0 :(得分:1)

请参阅Working with Outlook HTMLBody

Option Explicit
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    Dim StrAgnt As String

    StrAgnt = "<HTML><H2>The body  HTML.</H2><BODY>Type the message text here. </BODY></HTML>" & vbCrLf & vbCrLf & _
                "<P><FONT FACE=""Comic Sans MS"" size=""6"" color=""red""><B>TEST.</B></FONTt></P>" & vbCrLf & vbCrLf & _
                "<P><FONT FACE=""Times New Roman"" size=""4"" color=""blue""><i>TEST</i></FONT></P>" & vbCrLf & vbCrLf & _
                "<P><FONT FACE=""Arial"" size=""3"" color=""green"">TEST</FONT></P>" & vbCrLf & vbCrLf

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = StrAgnt
       .Display
    End With
End Sub

MSDN HTMLBody Property