Looking for a macro to create a text box with Arial 12 as the default font.
Looking for a macro to create a text box with Arial 12 as the default font.
Last edited by Xx7; 07-05-2011 at 04:00 PM.
Hello Xx7,
This macro adds an ActiveX TextBox to a worksheet and aligns it with the cell you specify. The sheet does not have to be the active sheet for the macro to work.
![]()
Sub AddTextBox(Rng As Range) Dim Height As Double Dim Left As Double Dim Top As Double Dim TxtBox As Object Dim Width As Double Dim Wks As Worksheet Set Wks = Rng.Parent Left = Rng.Left Top = Rng.Top Height = 22 Width = 76 Set TxtBox = Wks.OLEObjects.Add("Forms.TextBox.1", Left:=Left, Top:=Top, Width:=Width, Height:=Height) With TxtBox.Object .ForeColor = vbBlack .FontName = "Arial" .FontSize = 12 End With End Sub
Macro Example
This adds a TextBox to "Sheet1" and places the upper left corner of the TextBox in cell "G15".
![]()
Sub TestIt() AddTextBox Worksheets("Sheet1").Range("G15") End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Works great!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks