Formatting a Text String in VBA

RichardSabbara

New Member
Joined
Oct 4, 2019
Messages
2
I have the following macros that work:

Sub AAA_test_MAR()
Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
.Subject = "Monthly Action Report (MAR) "
.To = "richard.sabbara@xxx.com"
.CC = ""
.HTMLBody = MAR_Message_SECURE
.Attachments.Add ""
.Send
End With
End Sub

Function MAR_Message_SECURE() As String
MAR_Message_SECURE = "Please find attached your Monthly Action Report (MAR) for August. " & _
"<br/><p style='font-family:Arial;font-size:9'> </p>"
"We are going to sent out survey. " & _
"We want to hear from you! " & _
End Function

For the line "We are going to send out a survery. " I want this be bold, sky blue and 14 point font.
For the fline "We want to hear from you." I want to make this italics.

I am not sure how to do that.

Thank you,

Richard
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi and welcome to MrExcel forum!
Try this:

Rich (BB code):
Function MAR_Message_SECURE() As String
  
  Const Font1 = "<" & "span style='font-family:Arial;color:skyblue;font-weight:bold;font-size:14pt'" & ">"
  Const Font2 = "<" & "span style='font-style:italic;'" & ">"
  Const EndTag = "<" & "/" & "span" & ">"
  Dim s As String

  s = "Please find attached your Monthly Action Report (MAR) for August." & vbLf _
    & Font1 & "We are going to sent out survey." & EndTag & vbLf _
    & Font2 & "We want to hear from you!" & EndTag

  s = Replace(s, vbLf, "<" & "br /" & ">" & vbLf)
  
  MAR_Message_SECURE = s
  
  ' The below is just for smart testing.
  ' Copy text from Immediate window and paste into Excel sheet to see the result
  Debug.Print "<" & "body" & ">" & s & "<" & "/" & "body" & ">"
    
End Function
Regards
 
Upvote 0
You are welcome, thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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