How to format a line in my outlook msg using VBA?

lindalibinbin

New Member
Joined
Dec 23, 2013
Messages
6
Hi Everyone,

Complete VBA newbie here. I have the following code for sending out an outlook email with an attachment, and there's one line in the body (cells(9,2) particularly) I would like to bold+underline. Please help! Much appreciated.

Sub Email()
'
'
Dim OutApp As Object
Dim OutMail As Object
Dim FileName1 As String
Dim Msg As String, URL As String

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
FileName1 = Cells(12, 2)

On Error Resume Next
With OutMail
.to = Cells(3, 2)
.CC = Cells(4, 2)
.BCC = ""
.Subject = Cells(5, 2)
.Body = Cells(6, 2) & vbCrLf & vbCrLf & Cells(7, 2) & vbCrLf & Cells(8, 2) & vbCrLf & vbCrLf & Cells(9, 2) & vbCrLf & vbCrLf & Cells(10, 2) & vbCrLf & Cells(11, 2)
.Attachments.Add (FileName1)
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub


Thanks again!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi
Try
HTML:
[CODE].HTMLBody = "<p>" & Cells(6, 2) & "<br><br>" & Cells(7, 2) & "<br>" & Cells(8, 2) & "<br><br><b>" & Cells(9, 2) & "</b><br><br>" & Cells(10, 2) & "<br>" & Cells(11, 2) & "</p>"[/CODE]
Regards,
 
Last edited:
Upvote 0
Thanks for the reply. I don't quite understand though (sorry i'm very new at this). Do you mean to have the code written as the below (I changed cell locations)?

With OutMail
.to = Cells(48, 3)
.CC = Cells(49, 3)
.BCC = ""
.Subject = Cells(50, 3)
.HTMLBody = "" & Cells(51, 3) & "" & "" & Cells(52, 3) & "" & Cells(53, 3) & "" & "" & "" & Cells(54, 3) & "" & "" & "" & Cells(55, 3) & "" & Cells(56, 3)
.Attachments.Add (filename)
 
Upvote 0
oh I got it!! thank you very much. With your help I was able to play around with font, spacing and text size as well! Now my email looks more professional. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,267
Members
449,219
Latest member
daynle

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