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
Bookmarks