VBA with olMail Body Formatting

jfoBoston

New Member
Joined
Feb 8, 2018
Messages
4
Thanks in advance for any help.

I'm trying to create an email from an excel file. Currently works fine, however I'm looking to BOLD certain parts of the .Body string. It was suggested that I use .HTMLBody for some quicker easy coding, but I'm not that HTML savy and haven't been able to simply change a variable within the .Body string to contain the HTML bold code without it crashing everything.

Can this be done with the current olEmail format, or is HTML the only way to accomplish this? I'm looking for " Range("I21").Value" to be bold from the code below:

VBA Code:
Sub Email()

Dim olApp As Outlook.Application
Set olApp = CreateObject("outlook.application")


Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
    
With olMail

    .Body = Range("I3").Value & vbNewLine & vbNewLine & Range("I5").Value & vbNewLine & _
    vbNewLine & Range("I7").Value & vbNewLine & vbNewLine & Range("I9").Value & vbNewLine & vbNewLine & _
    Range("I11").Value & vbNewLine & vbNewLine & Range("I13").Value & vbNewLine & vbNewLine & _
    Range("I15").Value & vbNewLine & vbNewLine & Range("I17").Value & vbNewLine & vbNewLine & _
    Range("I19").Value & vbNewLine & vbNewLine & Range("I21").Value & vbNewLine & vbNewLine & Range("I23").Value
    
    olMail.SentOnBehalfOfName = "emailrequests"
    olMail.To = Range("C3").Value
    olMail.Subject = Range("E3").Value
    olMail.BCC = "emailrequests@xyzcorp.com" & ";" & Range("D10").Value


    
    olMail.Display
    
    End With
    
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this

VBA Code:
Sub Email()
  Dim olApp As Outlook.Application
  Dim olMail As Outlook.MailItem
  Set olApp = CreateObject("outlook.application")
  Set olMail = olApp.CreateItem(olMailItem)
    
  With olMail
    .HTMLBody = Range("I3").Value & "<br><br>" & Range("I5").Value & "<br><br>" & _
      Range("I7").Value & "<br><br>" & Range("I9").Value & "<br><br>" & _
      Range("I11").Value & "<br><br>" & Range("I13").Value & "<br><br>" & _
      Range("I15").Value & "<br><br>" & Range("I17").Value & "<br><br>" & _
      Range("I19").Value & "<br><br><b>" & Range("I21").Value & "</b><br><br>" & Range("I23").Value
    
    olMail.SentOnBehalfOfName = "emailrequests"
    olMail.To = Range("C3").Value
    olMail.Subject = Range("E3").Value
    olMail.BCC = "emailrequests@xyzcorp.com" & ";" & Range("D10").Value
    olMail.Display
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top