Textbox: highlight green, selected text

viktoryeung

New Member
Joined
Feb 6, 2005
Messages
17
Hi Gang, :)
Is it possible to set the textbox.backcolor = green, for only a portion of a textbox???
(I want the user to be able to highlight portions of text in a textbox)
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi!

No that's impossible.
But you can highlight parts of the text itself.

recording a macro you'll find code like this (I just enhanced it a bit)
(the "bbbbb" will be red)

Code:
Sub Macro2()
Dim rng As Range
Set rng = Range("D1")

With rng
.FormulaR1C1 = "aabbbbbaa"
    With .Characters(Start:=1, Length:=2).Font
        .Name = "Arial"
        .FontStyle = "Standaard"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    With .Characters(Start:=3, Length:=5).Font
        .Name = "Arial"
        .FontStyle = "Standaard"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = 3
    End With
    With .Characters(Start:=8, Length:=2).Font
        .Name = "Arial"
        .FontStyle = "Standaard"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
End With
End Sub

this can be reduced to:

Code:
Sub Macro2()
Dim rng As Range
Set rng = Range("D1")

With rng
.FormulaR1C1 = "aabbbbbaa"
.Characters(Start:=3, Length:=5).Font.ColorIndex = 3
End With

End Sub

can this give you some ideas?
kind regards,
Erik
 
Upvote 0
Impossible????
well i guess this cant be done through ExcelVBA, but maybe there might be an API call or something????
Comon! wheres the "Can Do" attitude! :biggrin:
 
Upvote 0
It is impossible to cross the sea by feet.
It is impossible to fly with you arms.

There could be complicated workarounds like.
type "aabbbbbaa" in B1
select A1 to C1
Format horizontal: center acroos selection
set column widths to 3
fill cell in middle with other color
OR
every character in another cell...

If you want a CANDO, knock the door of Bill Gates!

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,203,683
Messages
6,056,719
Members
444,887
Latest member
cvcc_wt

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