How to format text in a Text box using VBA code

S

Shane B

Hi All,

I have just started using VBA so this might be an easy question but
have been unable to find an answer so far in my searches.

I have created a text box and added text to it, even changed th
background colour all using VBA code. However I am unable to chang
the font bold, text size, and alignment using VBA code for the tex
box.

Can anyone help?

Also another question off the main topic, does anyone know how to tur
the "snap to grid" option on and off using VBA code in excel?

I am using Excel 97, its on a work computer and they have not upgrade
yet.

Any information would be greatly appreciated.

Thank you and hace a nice day.
Shane
 
T

Tom Ogilvy

In a textbox from the control toolbox toolbar, you don't - it isn't
supported. A textbox from the Forms toolbar, use the characters method.

For both questions, turn on the macro recorder and do it manually. Then
stop the recorder and look at the recorded code. This will give you great
insight into how to do it with VBA code.
 
G

Guest

Hi,
I did this on record new macro.
Range("A1").Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
 
T

Tom Ogilvy

Let me qualify my answer a little - I assumed you were doing Rich Text
Formats, but after rereading, that is not necessarily a valid assumption.
For a control toolbox toolbar textbox you can do:

Sub Macro3()
ActiveSheet.TextBox2.Font.Bold = False
ActiveSheet.TextBox2.Font.Size = 13
End Sub

for bold and size. for alignment, I don't think it is supported.

--
Regards,
Tom Ogilvy

Tom Ogilvy said:
In a textbox from the control toolbox toolbar, you don't - it isn't
supported. A textbox from the Forms toolbar, use the characters method.

For both questions, turn on the macro recorder and do it manually. Then
stop the recorder and look at the recorded code. This will give you great
insight into how to do it with VBA code.
 

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