TextBox is one of the UserForm control. You can select and drag TextBox on the UserForm. It is used to display text or edit existing text on the TextBox. TextBox can have static data or dynamic data. You can see how TextBox works and more details about UserForm TextBox Control on the UserForm in the following section.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

VBA TextBox Control on the UserForm

Please find more details about VBA ActiveX TextBox Control on the UserForm.

  1. Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
  2. Go To Insert Menu, Click UserForm. Please find the screenshot for the same.
  3. Drag the TextBox control on the Userform from the Toolbox. Please find the screenshot for the same.
  4. Click on the properties.
  5. On the left side find ‘Text’ from the available properties.
  6. On the right side mention as ‘Welcome!’.
  7. Like this you can add number of Text Box controls on the UserForm according to your requirement.

Add ActiveX Dynamic Text Box Control on the UserForm Using VBA

Please find the following steps and example code, it will show you how to add dynamic TextBox control on the userform.

  1. Add Text Box and CommandButton on the userform from the toolbox.
  2. Right click on the CommandButton, click properties
  3. Change the CommandButton caption to ‘Create_TextBox ’
  4. Double click on the CommandButton
  5. Now, it shows the following code.
  6. Private Sub CommandButton1_Click()
    End Sub
  7. Call the below procedure named ‘Add_Dynamic_TextBox ’ and find the below procedure to run.
  8. Private Sub CommandButton1_Click()
    Call Add_Dynamic_TextBox 
    End Sub

    Procedure to call in the CommandButton:

    Sub Add_Dynamic_TextBox()
    'Add Dynamic TextBox and assign it to object 'Lbl'
    Set lbl = UserForm2.Controls.Add("Forms.TextBox.1")
    'Assign TextBox Name
    lbl.Caption = "Dynamic TextBox"
    'TextBox Border Style
    lbl.BorderStyle = 2
    'TextBox Position
    lbl.Left = 10
    lbl.Top = 10
    End Sub
  9. Now, click F5 to run the macro, click ‘Create_TextBox ’ button to see the result.
  10. You can see the created dynamic Text Box which is shown in the following screen shot.
  11. Clear ActiveX TextBox Control Using VBA

    Please find the below code it will show you how to clear ActiveX Text Box control. In the below example ‘TextBox1’ is the text box name.

    Sub Clr_TxtBx()
    TextBox1.Text = ""
    End Sub

    Delete TextBox Control on the UserForm using VBA

    Please find the below code, it will show you how to delete or remove the control on the UserForm. In the below example, its deleting the TextBox named ‘New TextBox’ which is on the UserForm named ‘UserForm4’. We can use Remove method to delete the controls which are created during run time. Controls which are created during design time cannot be deleted using this method. Please find the below example and screen shots for better understand.
    Code 1: Adding control During Run Time

    Private Sub CommandButton1_Click()
    'We can use Add method to add the new controls on run time
    Set lblBtn = Me.Controls.Add("Forms.TextBox.1")
    With lblBtn
    .Top = 20
    .Left = 20
    .Caption = "New TextBox"
    .Name = "lblNew1"
    End With
    MsgBox "New TextBox Added"
    End Sub

    Please find the below screen shot for your reference for the above macro and its output.
    When we click on Add Command Button:

    Code 1: Deleting or Removing Text Box control which is created during run time.

    Private Sub CommandButton2_Click()
    'We can use Remove method to delete the controls which are created during run time
    'Note: Controls which are created on design time cannot be deleted using this method
    Me.Controls.Remove ("lblNew1")
    MsgBox "New TextBox Deleted"
    End Sub

    Please find the below screen shot for your reference for the above macro and its output.
    When we click on Delete Command Button:


Related pages

vba getfilenameaccess 2013 activex controlsexcel vba macroexcel vba pivotunmerge all cellssample xlsm file downloadvlookup between two sheetshow to sort excel sheets alphabeticallyvba vlookuptop oop interview questionsvba update querypull data from another workbooksas macro programming for beginnersinterview questions and answers for freshercombobox tutorialhow can i hide columns in excelvlookup function explainedhow to create a new worksheet in excelexcel macro copy data from one workbook to anotherproject checklist template excelunprotect worksheet excelvba excel connection stringmeaning of offset in hindivba run applicationhow to join cells in excelexcel 2010 macro recorderaccess vba for loopexcel remove duplicate cellscopy sheet vbaform excel vbactrl shift d excelhow to multiply a column in excellearning vba for excelclose workbook vbalock selected cells in excel 2007identify duplicate records in excelexcel vba cell offsetexcel vba select sheetexcel most useful formulasisna with vlookupvba formsexcel fix columnssorting data in excel 2007excel 2010 pivot table calculated fieldvba excel dynamic arrayhyperlink shortcut keyapplication workbooksmerge multiple rows in excelvlookup with if conditionbubble chart excel 2010how to add chart title in excelexcel remove duplicate columnshlookup in excel 2010excel vba range clearexcel 2007 shortcut keysquery sql server from excelmerge multiple excel sheets into one sheetshortcut key for insert rowunprotect excel without passwordproject milestone templateexcel chart stylessql in sasincrease column width in excelexcel worksheet activateswot chart templateddl sql statementsexcel vba status bar progresshyperlink excel 2007developer tab excel 2007button macro excelsql ddl dml dcl commandsadvanced excel vba examplesunprotect sheet forgot passworduserform controls