VBA - Color some characters one color and other characters another in a textbox

i_excel

Board Regular
Joined
Jun 4, 2015
Messages
113
Hi

I am looking to insert a textbox that has characters of nonuniform color. I hope those red and blue"o"s clarified the task at hand.

I have found three web sites that seem to pose a solution:
1. Using a standard textbox: vba changing the color of some of the text in a textbox;
2. Using a richtextbox: http://www.vbforums.com/showthread.php?666655-changing-a-color-for-specific-string-in-text-box; and
3. Another I don't know where to start with:http://stackoverflow.com/questions/...er-in-textbox-in-different-color-in-vba-excel.

I would prefer to use the standard textbox code because I already have code that works with it (you maybe have already guessed that I am new to VBA, but this point must confirm it). That code inserts, names, changes the background and line color of, and populates with text, a textbox. But I am at a loss as to how to use the standard textbox code to heterogeneously color its text. And indeed I have seen enough posters declaring it impossible to shake my confidence.

I was hoping that one fine forum member might help me out here.. Let me know if my question is unclear and I will do my best to refine it.

Any advice would be much appreciated.

i_excel
 
Last edited:

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

i_excel

Board Regular
Joined
Jun 4, 2015
Messages
113
Readers - I apologise. No sooner did I post did I discover it. For the benefit of others:

Code:
 With ActiveSheet.Shapes("TextBox Name")
.TextFrame.Characters.Text = "color me crazy"
.TextFrame2.TextRange.Characters(7, 2).Font.Fill.ForeColor.RGB = RGB(217, 217, 217) 
End with

The code should color "me" red, where "color me crazy" is the text in the textbox named "TextBox Name".

Apologies again

i_excel
 

Watch MrExcel Video

Forum statistics

Threads
1,123,331
Messages
5,601,002
Members
414,419
Latest member
JRDunya

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
Top