Rey Taino
Rey Taino

Reputation: 179

Make a part of my email body text bold with using .body instead of .htmlbody in Word VBA

I am trying to bold specific text within the body of my email VBA. In it's current state, I am unable to format any text under .body.

However, when I change to .html body, I am able to bold text. For example, if I use "< b>JOB NUMBER", the text "JOB NUMBER" is in bold, but the entire body of my email loses all line spaces.

Your help will be much appreciated. Thanks

    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 = "[email protected];"
    .CC = "[email protected];" & "[email protected];"
    .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

Upvotes: 4

Views: 18309

Answers (1)

Parfait
Parfait

Reputation: 107652

You can continue to use HTML, simply replace the carriage returns with html's <br> for line break. Remember every inline markup (no css) to style html content is valid. So you have free range of fonts, colors, sizes, even web images!

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    

Alternatively, use an html table for better alignment:

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

Upvotes: 6

Related Questions