How to add an ActiveX text box on a worksheet, either manually, or with a macro
In an Excel worksheet, you can add text boxes from the ActiveX Controls toolbox on the Ribbon's Developer tab. The text box can be linked to a worksheet cell.
To manually create the Text Box on the worksheet, follow these steps:
Instead of manually adding an ActiveX Text Box to the worksheet, you can add one with programming.
In the following macro, a text box is added on sheet 2, and formatted, and linked to cell A2 on the worksheet.
Sub AddTextBox() Dim ws As Worksheet Dim oTB As Object Set ws = Worksheets("Sheet2") Set oTB = ws.OLEObjects.Add(ClassType:="Forms.TextBox.1") With oTB .Name = "MyTB" .LinkedCell = "$A$2" .Left = ws.Range("B2").Left .Top = ws.Range("B2").Left .Width = ws.Range("B2").Width .Height = ws.Range("B2").Height .Object.BackColor = RGB(204, 204, 255) .Object.ForeColor = RGB(0, 0, 255) .Object.Text = "Hello" End With End Sub
Don't miss my latest Excel tips and videos! Click OK, to get my weekly newsletter with Excel tips, and links to other Excel news and resources.
Search Contextures Sites
Last updated: June 15, 2017 1:48 PM
Contextures RSS Feed