Format specific text in Outlook

送分小仙女□ 提交于 2019-12-10 22:14:25

问题


I need to format the specific String value which was acquired from Excel in Outlook.

Once the value is provided by Excel, macro will then append that value in the email message.

I tried testing and setting the value to BOLD but all of the contents of the message became BOLD. How do I format the value in such a way I can use the font type, size and color to my liking?

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

回答1:


See 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



来源:https://stackoverflow.com/questions/34914664/format-specific-text-in-outlook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!