How to Insert Text Boxes With VBA Code in Excel


The text box is the element on a form that allows you to enter data in the user application. You can use input from the text box in your Visual Basic for Application (VBA) procedure. An Excel VBA text box is an empty field on a worksheet that you can fill in with the text. The VBA for Excel text box control includes design properties that gives you the ability to set the font, color of the background and the type of the box border.

  • Click "Start," "Microsoft Visual Basic for Applications."

  • Enter the following code in the open window:

    Sub Macro1()

    ' Macro1 Macro

    Dim chtTemp As Chart

    Dim objTemp As Object

    Set chtTemp = ActiveSheet.ChartObjects(1).Chart

    Set objTemp = chtTemp.Shapes.AddTextbox

    (msoTextOrientationHorizontal, 1, 1, 150, 20)


    Selection.Formula = "='" & chtTemp.Parent.Parent.Name & "'!A1"


    End Sub

  • Click "File," "Save" to add the VBA script to your spreadsheet application.

Related Searches


  • Photo Credit Photodisc/Photodisc/Getty Images
Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!