PDA

View Full Version : Color text in textbox?



doctortt
05-07-2011, 04:13 PM
Hi, can someone help? I want to color a few words in the textbox.


Textbox1.Value = "Hello, do you want fries with that?"

i.e. how would you just color the word, fries, in red?

Thanks

Chabu
05-08-2011, 01:32 PM
use the characters property of a cell

With Worksheets("Sheet1").Range("A1")
.Value = "abcdefg"
.Characters(3, 1).Font.Bold = True
End With

ntrauger
05-08-2011, 02:59 PM
Not possible with a single textbox. This would require a rich textbox control (such as Microsoft Rich Textbox Control 6.0 (SP6)) or fancy control weaving and coding. Either method opens a can of worms, though the latter method may be less of a headache. See http://support.microsoft.com/kb/838010. If you have a rich textbox control installed, you'll find it under menu "Tools>Additional Controls...".

Chabu
05-08-2011, 03:08 PM
Indeed, I did not read the question properly.
What I posted works for cells in a sheet but not for a textbox.

Paul_Hossler
05-11-2011, 04:32 PM
Bit round about, but you can format the text in a cell either manually or via VBA, copy it as a picture, and put it into an image control on your user form

Not a textbox, but might work for you

Paul

mikerickson
05-11-2011, 04:50 PM
An easier workaround would be to have a border-less Label with the red word in in placed directly above the textbox. A Label_OnClick event would transfer focus to the text box...It would be clunky programming and might not be worth it.

A Label as an underscore might be an easier highlight.
With Label1
.BorderColor = RGB(0, 0, 0)
.BorderStyle = fmBorderStyleSingle
.Height = 1
.ZOrder 0
.Top = TextBox1.Top + TextBox1.Height - 4
End With

Kenneth Hobs
05-12-2011, 08:36 AM
Why not take advantage of the Suite's power and use an MSWord object?

Paul_Hossler
05-12-2011, 11:59 AM
Mike - I had thought about that, but I can never get things lined up right

It just seems easier to format a cell with the test and the specia formatting, and treat it as an image

I'm not thrilled with it either

Paul