Choose your language

VBA UserForm


The UserForm is a custom dialog box made through VBE. This box allows the input of user data in a controlled and user-friendly manner.


Adding a UserForm

  1. Open the Visual Basic Editor (VBE - Alt+F11)
  2. Right-click anywhere in the VBAProject window
  3. Select Insert
  4. Select UserForm
Add UserForm

Once you have done this, you will see the UserForm in its edit mode.

Edition UserForm

If you exit the layout editing mode, simply double-click on the project to return to it.

Edit Userform

Toolbox

Through the toolbox it is possible to edit the Layout of the UserForm and create the interface for the user. If the toolbox is not showing up, just click on the icon of the Toolbar.

Toolbox UserForm

The standard VBA toolbox for UserForms provides the following buttons:

  1. () Allows you to change the position of layout items
  2. () Adds a text that can not be changed by the user when the UserForm is called It helps you describe the controls to the user
  3. () Allows the user to enter (or change) text
  4. () It is a list of options from which the user can choose, and it is possible for the user to include an item
  5. () It is a list of options from which the user can choose, and it is not possible for the user to include an item
  6. () Used to create a selection with multiple options
  7. () It allows to select mutually exclusive options, which will return the values True or False E.g. Yes or No
  8. () Performs an action when first clicked and a different action when clicked the second time. It transits between two states E.g. On or OFF
  9. () Used to group controls that can work together or have common factors Widely used to group option buttons
  10. () Adds a button that can execute a code when clicked
  11. () Adds tabs that can contain the control sets, but different tabs will not have different controls
  12. () Adds tabs that can contain the control sets, and different tabs may have different controls
  13. () It is used to increment or decrement a value shown by another control. This increment can be previously defined
  14. () Similar to the scrollbar, it also serves to increase or decrease values, however with the possibility of "dragging"
  15. () Provides the ability to display an external image on the UserForm
  16. () Allows the user to select or enter a defined range from a worksheet

To add an element to the Userform, simply select the appropriate button on the toolbox, click and drag the mouse on the UserForm to set its size.

Userform Add Button

The next topic (First UserForm Layout) will address in more detail the layout construction.

The controls entered in the UserForm are of the ActiveX type.

ActiveX Controls allow you to enter and configure VBA codes individually.

You can add ActiveX Controls directly on spreadsheets: Developer tab $\rightarrow$ Insert $\rightarrow$ ActiveX Controls.



SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.

Excel ® is a registered trademark of the Microsoft Corporation.

© 2019 SuperExcelVBA | ABOUT

Protected by Copyscape