Excel – How to set a Text Highlight Color—not cell shading—for a specific text within an Excel cell

microsoft excelmicrosoft-excel-2013microsoft-office

How could I set a Text Highlight Color—not cell shading—for a specific text within an Excel cell?


Illustrative Example:

This is a screenshot from OneNote of what I need to do on Excel also: link

#A: This cell has a shading color (grey) and there is not text hightlighted.

#B: this cell has a shading color (light blue) and word2,3 are higlighted with (green) (This is what I need to do)


Note:

What I mean by Text Highlight Color isn't related to a VBA or Macro scripts, I just mean the decorative meaning to style text manually.

Best Answer

I had this same issue but I couldn't use the Review Ink Tools method in the above answer because I had to automate the process in VBA.

My workaround was to create inline textboxes the height of the cell and to set the background of the textbox to the highlight color (or white) that I wanted, see picture below:

.

Here's my VBA code that produces these textboxes in the active cell for anyone that's interested. The textbox will automatically resize in width to fit the text:

' Create an inline textbox in the active cell and return it
Function InlineTextBox(s As String, rgb As Long, left As Integer) As Shape
    Set InlineTextBox = Worksheets(1).Shapes.AddTextbox(msoTextOrientationHorizontal, _
                    left, ActiveCell.Top, 50, 15)
    InlineTextBox.TextFrame.Characters.Text = s
    InlineTextBox.TextFrame2.WordWrap = False
    InlineTextBox.TextFrame.MarginLeft = 2
    InlineTextBox.TextFrame.MarginRight = 0
    InlineTextBox.TextFrame.MarginTop = 0
    InlineTextBox.TextFrame.MarginBottom = 0
    InlineTextBox.Line.Visible = msoFalse
    InlineTextBox.TextFrame2.AutoSize = msoAutoSizeShapeToFitText
    InlineTextBox.Height = 15
    InlineTextBox.Fill.ForeColor.rgb = rgb
End Function
Related Question