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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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