ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to format text in a Text box using VBA code (https://www.excelbanter.com/excel-programming/316786-how-format-text-text-box-using-vba-code.html)

Shane B

How to format text in a Text box using VBA code
 

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

--
Shane
-----------------------------------------------------------------------
Shane B's Profile: http://www.excelforum.com/member.php...fo&userid=1646
View this thread: http://www.excelforum.com/showthread.php?threadid=27820


Tom Ogilvy

How to format text in a Text box using VBA code
 
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.

--
Regards,
Tom Ogilvy

"Shane B" wrote in message
...

Hi All,

I have just started using VBA so this might be an easy question but I
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 the
background colour all using VBA code. However I am unable to change
the font bold, text size, and alignment using VBA code for the text
box.

Can anyone help?

Also another question off the main topic, does anyone know how to turn
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 upgraded
yet.

Any information would be greatly appreciated.

Thank you and hace a nice day.
Shane B


--
Shane B
------------------------------------------------------------------------
Shane B's Profile:

http://www.excelforum.com/member.php...o&userid=16467
View this thread: http://www.excelforum.com/showthread...hreadid=278207




No Name

How to format text in a Text box using VBA code
 
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

-----Original Message-----

Hi All,

I have just started using VBA so this might be an easy

question but I
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 the
background colour all using VBA code. However I am

unable to change
the font bold, text size, and alignment using VBA code

for the text
box.

Can anyone help?

Also another question off the main topic, does anyone

know how to turn
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 upgraded
yet.

Any information would be greatly appreciated.

Thank you and hace a nice day.
Shane B


--
Shane B
----------------------------------------------------------

--------------
Shane B's Profile: http://www.excelforum.com/member.php?

action=getinfo&userid=16467
View this thread:

http://www.excelforum.com/showthread...hreadid=278207

.


Tom Ogilvy

How to format text in a Text box using VBA code
 
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" wrote in message
...
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.

--
Regards,
Tom Ogilvy

"Shane B" wrote in message
...

Hi All,

I have just started using VBA so this might be an easy question but I
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 the
background colour all using VBA code. However I am unable to change
the font bold, text size, and alignment using VBA code for the text
box.

Can anyone help?

Also another question off the main topic, does anyone know how to turn
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 upgraded
yet.

Any information would be greatly appreciated.

Thank you and hace a nice day.
Shane B


--
Shane B
------------------------------------------------------------------------
Shane B's Profile:

http://www.excelforum.com/member.php...o&userid=16467
View this thread:

http://www.excelforum.com/showthread...hreadid=278207







All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com