+ Reply to Thread
Results 1 to 12 of 12

Change Font formatting mid-sentence of HTMLBody Outlook mail

Hybrid View

askpcguy Change Font formatting... 07-30-2014, 11:12 PM
Domenic Re: Change Font formatting... 07-30-2014, 11:55 PM
askpcguy Re: Change Font formatting... 07-31-2014, 12:22 AM
Domenic Re: Change Font formatting... 07-31-2014, 12:43 AM
askpcguy Re: Change Font formatting... 07-31-2014, 01:10 AM
Domenic Re: Change Font formatting... 07-31-2014, 07:31 AM
askpcguy Re: Change Font formatting... 07-31-2014, 09:47 PM
  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Washington
    MS-Off Ver
    2010
    Posts
    37

    Change Font formatting mid-sentence of HTMLBody Outlook mail

    Hello everyone!

    I've got the following code (thanks in part to some helpful folks here) which is working but I'm having a tough time changing the font formatting. I'm trying to add code to change the font color after Red to another color but have not found any examples online. Everything mentions the paragraph styling which when I use will put the text on a new paragraph.

    --Also, how can I space the table elements? Currently there is almost no spacing and I'd want to put a few tabs between the columns.

    Private Sub CommandButton4_Click()
      Dim OutlookApp As Object
      Dim mItem As Object
      Dim MyLink As String
      MyLink = "http://SomeWebSiteHereOrPlaceHolder="
        Set OutlookApp = CreateObject("Outlook.Application")
        Set mItem = OutlookApp.CreateItem(0)
        With mItem
        .To = "PlaceHolder"
        .Subject = "PlaceHolder"
        .HTMLBody = "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>Example <Change font color HERE>Text #1</CHANGE></I></H2></P>"
        .HTMLBody = .HTMLBody & "<TABLE><TR><TD><B>Example Text #2</TD></B><a href=""" & MyLink & _
            TextBox1.Value & """>" & TextBox1.Value & "</a>" & _
            "<TR><TD><B>Status:</TD></TR></B>" & ComboBox1.Text & _
            "<TR><TD><B>Date/Time Reported:</TD></TR></B>" & TextBox2.Text & _
            "<TR><TD><B>Impact Summary:</TD></TR></B>" & TextBox3.Text & _
            "<TR><TD><B>Locations Impacted:</TD></TR></B>" & TextBox4.Text & _
            "<TR><TD><B>Incident Manager:</TD></TR></B>" & TextBox5.Text & _
            "<TR><TD><B>Actions / Progress:</TD></TR></B>" & TextBox6.Text & _
            "<TR><TD><B>Root Cause:</TD></TR></B>" & TextBox7.Text & _
            "</TABLE></BODY></HTML>"
        .Importance = 2
        .Display
      End With
    End Sub
    Last edited by askpcguy; 07-31-2014 at 05:17 PM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    To change the colour for text within a sentence, try...

    <span style="color: rgb(0, 0, 102);">your text</span>

    Change the colour, accordingly.

    Hope this helps!

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    Washington
    MS-Off Ver
    2010
    Posts
    37

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    Trying that give an error on color.

    "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>FlashAlert</I></H2></P><span style="color:rgb(31,73,125);">This is another color</span>
    However this works but the text is on another line
    span style='color:rgb(31,73,125)'
    Last edited by askpcguy; 07-31-2014 at 12:22 AM. Reason: forgot code blocks

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    Try...

    "<p>This is another <span style=""color:rgb(31,73,125);"">sentence</span> where one word has a different font color.</p>"

  5. #5
    Registered User
    Join Date
    07-16-2014
    Location
    Washington
    MS-Off Ver
    2010
    Posts
    37

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    That works but still puts the 2nd color text on a different line. Happens even if I remove the
    <P> tags

  6. #6
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    Try replacing...

    .HTMLBody = "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>Example <Change font color HERE>Text #1</CHANGE></I></H2></P>"
    with

    .htmlbody = "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>Example <span style=""color:rgb(31,73,125);"">Text #1</span></P></I></H2>"

  7. #7
    Registered User
    Join Date
    07-16-2014
    Location
    Washington
    MS-Off Ver
    2010
    Posts
    37

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    Quote Originally Posted by Domenic View Post
    Try replacing...

    .HTMLBody = "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>Example <Change font color HERE>Text #1</CHANGE></I></H2></P>"
    with

    .htmlbody = "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>Example <span style=""color:rgb(31,73,125);"">Text #1</span></P></I></H2>"
    That did the trick! Here's my final code. Now I've got to find a way to add some space between the table columns. I'd think by now I owe someone a lunch!!!
        .HTMLBody = "<HTML><BODY><H2><I><P Style='font-family:Arial;font-size:18pt;color:red'>New Alert"
        .HTMLBody = .HTMLBody & "<Span Style=""Color:RGB(31,73,125);"">TextColor2-On-Same-Line!!!!</SPAN></P></I></H2>"
        .HTMLBody = .HTMLBody & "<TABLE><TR><TD><B>Incident Report Detail:</TD></B><a href=""" & MyLink & _
            TextBox1.Value & """>" & TextBox1.Value & "</a>" & _
            "<TR><TD><B>Status:</TD></TR></B>" & ComboBox1.Text & _
            "<TR><TD><B>Date/Time Reported:</TD></TR></B>" & TextBox2.Text & _
            "<TR><TD><B>Impact Summary:</TD></TR></B>" & TextBox3.Text & _
            "<TR><TD><B>Locations Impacted:</TD></TR></B>" & TextBox4.Text & _
            "<TR><TD><B>Incident Manager:</TD></TR></B>" & TextBox5.Text & _
            "<TR><TD><B>Actions / Progress:</TD></TR></B>" & TextBox6.Text & _
            "<TR><TD><B>Root Cause:</TD></TR></B>" & TextBox7.Text & _
            "</TABLE></BODY></HTML>"
        .Importance = 2

  8. #8
    Registered User
    Join Date
    07-16-2014
    Location
    Washington
    MS-Off Ver
    2010
    Posts
    37

    Re: Change Font formatting mid-sentence of HTMLBody Outlook mail

    Just an update, been hammering away at VBA but I can say the output looks polished and great. The VBA code however is totally different. Posting code here should anyone want to mess with tables, font formatting within the HTMLBody for an Outlook email.

    Private Sub CommandButton4_Click()
      Dim OutlookApp As Object
      Dim mItem As Object
      Dim oLinky As String, MyText As String
    oLinky = "http://GetYourOwnURLToPutHere.com"
    MyText = "This is an example of long text which we don't want to see in the HTMLBody"
        Set OutlookApp = CreateObject("Outlook.Application")
        Set mItem = OutlookApp.CreateItem(0)
        With mItem
        .To = "PlaceHolder"
        .Subject = "PlaceHolder"
        .HTMLBody = "<HTML><BODY><H2><I>"
        .HTMLBody = .HTMLBody & "<P Style=""font-family:Arial;font-size:18pt;color:red;"">FlashAlert"
        .HTMLBody = .HTMLBody & "<Span Style=""Color:RGB(31,73,125);""> - Important IT Service Bulletin</SPAN></H2></P>"
        .HTMLBody = .HTMLBody & "<Span Style='font-family:Arial;font-size:12pt;Color:blue'>" & MyText & "</SPAN></I>"
        .HTMLBody = .HTMLBody & "<table style=""font-family: Arial; font-size: 10pt; text-align: left;"" border=""0""" & _
            "cellpadding=""1"" cellspacing=""9"">" & "<TDBODY>" & "<TR>" & _
            "<TD Style=""font-weight: bold; width: 400px;"">Incident Report Detail:</TD>" & _
            "<TD Style=""width: 100px""><a href=""" & oLinky & _
            TextBox1.Value & """>" & TextBox1.Value & "</a></TD>" & "</TR>" & _
             "<TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Status:</SPAN></TD>" & _
            "<TD>" & ComboBox1.Text & "</TD>" & "</TR>" & _
             "<TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Date/Time Reported:</SPAN></TD>" & _
            "<TD>" & TextBox2.Text & "</TD>" & "</TR>" & _
             "<TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Impact Summary:</SPAN></TD>" & _
            "<TD>" & TextBox3.Text & "</TD>" & "</TR>" & _
             "<TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Locations Impacted:</SPAN></TD>" & _
            "<TD>" & TextBox4.Text & "</TD>" & "</TR>" & _
             "<TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Incident Manager:</SPAN></TD>" & _
            "<TD>" & TextBox5.Text & "</TD>" & "</TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Actions / Progress:</SPAN></TD>" & _
            "<TD>" & TextBox6.Text & "</TD>" & "</TR>" & _
            "<TD><Span Style=""font-weight: bold;"">Root Cause:</SPAN></TD>" & _
            "<TD>" & TextBox7.Text & "</TD>" & "</TR>" & "</TABLE></BODY></HTML>"
        .Importance = 2
        .Display
      End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Change font size of text in mail VBA code
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2013, 12:51 PM
  2. Change of formatting in a sentence to subscript
    By Sc0tt1e in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2013, 05:50 AM
  3. Change of formatting in a sentence to subscript
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2013, 05:50 AM
  4. change e-mail font default color
    By mvan in forum Excel General
    Replies: 1
    Last Post: 04-04-2006, 06:35 PM
  5. outlook htmlbody
    By Erin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2005, 03:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1