How to Use the VBA Textbox Properties in Excel – Easy Steps


What Is a VBA TextBox?

A TextBox is a box that receives data. It is a part of the UserForm.

Excel VBA TextBox

To insert a TextBox in a VBA UserForm:


  • Hold Alt + F11 to open the Microsoft Visual Basic Applications window.
  • Click Insert and select UserForm.

  • The UserForm is created.

  • Create a TextBox.

Insert TextBox in VBA UserForm

  • A “+” icon is displayed. Drag it to create the TextBox.

Read More: How to Hide Textbox Using Excel VBA

Properties of a VBA TextBox in Excel

Press F4 to display the properties of the TextBox.

excel vba textbox properties

Properties include Name, Color, Border Color, Border Style, Cycle, Font, Height, Picture Alignment, ScrollBars, Tag, Width, Zoom, and many others.

Here, Name and Caption were changed.

Using the VBA TextBox Properties in Excel


 Step 1- Select the Dataset

This is the sample dataset.

excel vba textbox properties Dataset

 Step 2 – Insert a Label and a TextBox in Excel VBA

  • Select Label in the Toolbox to draw a Label in the UserForm.

Draw Label and TextBox in Excel VBA

  • Insert a TextBox and change the Label name.

  • In TextBox Properties, change the name of the TextBox.

  • Draw one more Label and a TextBox.
  • Name the Label as Location and the TextBox as EmployeeLocationTextBox.

  • Go to the Toolbox and select CommandButton.

  • Change the name of the button to Submit.

  • Press F5 key to run the UserForm.

excel vba textbox properties

Step 3 – Enter a VBA Code in the TextBox

  • Go to the UserForm and double-click the Submit button.

  • An auto sub will be displayed.

  • Enter the following code into the Visual Basic Editor.
Private Sub CommandButton1_Click()
  Range("B5") = Me.EmployeeNameTextBox
  Range("C5") = Me.LocationTextBox
  Unload Me
End Sub

Insert VBA Code to TextBox in Excel

  • Press F5 to run the code: the Employee Info dialog box will be displayed.

excel vba textbox properties

Step 4 – Enter Data in the TextBox

  • Enter data and click Submit.

Input Data with VBA TextBox in Excel

  • Data will automatically be inserted into the selected Range.

Read More: How to Add Text to Textbox Using Excel VBA

Final Output

Change the Range of the VBA code to change the data input location. Repeat Step 4 to add more data.

This is the output.

excel vba textbox properties

Read More: How to Use VBA to Change Textbox Text in Excel

Download Practice Workbook

Download the workbook.

Related Articles

Get FREE Advanced Excel Exercises with Solutions!


Mehedi Hasan
Mehedi Hasan

Mehedi Hasan, a BSc graduate in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, plays a pivotal role as an Excel & VBA Content Developer at ExcelDemy. Fueled by a profound passion for research and innovation, he actively engages with Excel. In his capacity, Mehedi not only adeptly tackles intricate challenges but also showcases enthusiasm and expertise in navigating tough situations with finesse, underscoring his unwavering dedication to consistently delivering exceptional and high-quality content. He... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF