使用.body而不是Word VBA中的.htmlbody,使我的电子邮件正文文本的一部分变为粗体

时间:2016-06-08 17:37:32

标签: vba email word-vba outlook-vba

我正在尝试在我的电子邮件VBA正文中加粗特定文字。在其当前状态下,我无法格式化.body下的任何文字。

但是,当我更改为.html body时,我可以加粗文字。例如,如果我使用“< b> JOB NUMBER”,则文本“JOB NUMBER”以粗体显示,但我的电子邮件的整个正文都会丢失所有行空格。

非常感谢您的帮助。感谢

    Private Sub sendemail_Click()


Dim OL              As Object
Dim EmailItem       As Object
Dim Doc             As Document

Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save

With EmailItem
    .Subject = "QDR" & " " & TextBox22.Value & "_" & TextBox21.Value & "_" &    ComboBox2.Value & "_" & combobox1.Value
    **.Body** = "Attached QDR Request form is for the following: " & vbCrLf & _
    "" & vbCrLf & _
    "JOB NUMBER: " & vbCrLf & _
    TextBox21.Value & vbCrLf & _
    "" & vbCrLf & _
    "QDR NUMBER: " & vbCrLf & _
    TextBox22.Value & vbCrLf & _
    "" & vbCrLf & _
    "CONDITION: " & vbCrLf & _
    combobox1.Value & vbCrLf & _
    "" & vbCrLf & _
    "HARTNESS PART NUMBER: " & vbCrLf & _
    TextBox23.Value & vbCrLf & _
    "" & vbCrLf & _
    "REQUIRED DATE: " & vbCrLf & _
    TextBox31.Value & vbCrLf & _
    "PART REQUIRED SOONER THAN SET LEAD TIME: " & vbCrLf & _
    TextBox30.Value & vbCrLf & _
    "" & vbCrLf & _
    "BRIEF DESCRIPTION OF REQUEST: " & vbCrLf & _
    TextBox25.Value


    .To = "XXXXX@XXXXX.com;"
    .CC = "XXXXX@XXXXX.com;" & "XXXXX@XXXXX.com;"
    .Importance = olImportanceNormal 'Or olImportanceHigh Or olImportanceLow
    .Attachments.Add Doc.FullName
    .Display
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing


End Sub

EXAMPLE PICTURE

1 个答案:

答案 0 :(得分:3)

您可以继续使用HTML,只需用html的<br>替换回车换行。请记住,样式html内容的每个内联标记(无css)都是有效的。所以你有免费的字体,颜色,大小,甚至是网络图像!

msg = "Attached QDR Request form is for the following: <br><br>" _
      & "<b> JOB NUMBER:</b><br>" _
      & TextBox21.Value & "<br><br>" _
      & "<b> QDR NUMBER: </b><br>" _
      & TextBox22.Value & "<br><br>" _
      & "<b> CONDITION: </b><br>" _
      & combobox1.Value & "<br><br>" _
      & "<b> HARTNESS PART NUMBER: <br>" _
      & TextBox23.Value & "<br><br>" _
      & "<b> REQUIRED DATE: </b><br><br>" _
      & "PART REQUIRED SOONER THAN SET LEAD TIME: <br>" _
      & TextBox30.Value & "<br><br>" _
      & "<b>BRIEF DESCRIPTION OF REQUEST: </b><br>" _
      & TextBox25.Value

...
.HTMLBody = msg    

或者,使用html表进行更好的对齐:

msg = "Attached QDR Request form is for the following: <br><br>" _
      & "<table>" _
      & "<tr><td><b> JOB NUMBER: </b></td><td>" & TextBox21.Value & "</td></tr>" _
      & "<tr><td><b> QDR NUMBER: </b></td><td>" & TextBox22.Value & "</td></tr>" _
      & "<tr><td><b> CONDITION: </b></td><td>" & combobox1.Value & "</td></tr>" _
      & "<tr><td><b> HARTNESS PART NUMBER: <b></td><td>" & TextBox23.Value & "</td></tr>" _
      & "<tr><td><b> REQUIRED DATE: </b></td></tr>" _
      & "<tr><td> PART REQUIRED SOONER THAN SET LEAD TIME: </td><td>" & TextBox30.Value & "</td></tr>" _
      & "<tr><td> BRIEF DESCRIPTION OF REQUEST: </td><td>" & TextBox25.Value & "</td></tr>" _
      & "</table>"

...
.HTMLBody = msg