bold/italic formatting in userform textbox

K

Katherine

Is it possible to apply bold or italic formatting to something keyed into a
textbox in a userform, either by a shortcut key or coding a button on the
form to bold/italicise a selection?
 
B

Bryan

Sure,

Private Sub CommandButton1_Click()
Me.TextBox1.Font.Bold = True
Me.TextBox1.Font.Italic = True
End Sub

HTH!
....Bryan
 
J

Jay Freedman

Hi Katherine,

If you always want the contents of the textbox to be formatted that way, you
can set the formatting at design time and you won't need any code. Select
the textbox, go to the Properties pane, and click the Font item. A button
with "..." appears to the right of the font name; click it to open the
standard Font Properties dialog. Choose whatever formatting you want --
font, weight, size, color -- and click OK.

You need code in a Click() procedure or in the TextBox1_Change() procedure
only if you want to change the formatting depending on some other
condition -- for example, only if the text is too long, or contains certain
characters.

If you want only part of the text in the box to be italic or bold, I don't
think that's possible in an ordinary textbox. There's a type of control
called a Rich Edit textbox, which has much more formatting flexibility.
Unfortunately, you can't use the Microsoft Rich Edit control in recent
versions of Office because it isn't secure, and VBA won't let you place one
on a userform. You may be able to find a signed Rich Edit control from a
third-party vendor.
 
S

Steve Lang

Hi Jay and Katherine,

there is a work around so you can use the Richtext box. On the development
machine you need to change a specific Registry Setting:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX
Compatibility\{3B7C8860-D78F-101B-B9B5-04021C009402}

Change the "Compatibility Flags" DWord value to 0 (0x400 is a kill bit)

Now you will be prompted to trust loading the control and it will run.

It works for me!

HTH and have a great day!

Steve
 
J

Jay Freedman

Thanks, Steve, that's a great help. Now I'll have to go Google the
rest of the left-out---in-the-cold controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top