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
- Open the Visual Basic Editor (VBE - +)
- Right-click anywhere in the VBAProject window
- Select Insert
- Select UserForm
Once you have done this, you will see the UserForm in its edit mode.
If you exit the layout editing mode, simply double-click on the project to return to it.
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.
The standard VBA toolbox for UserForms provides the following buttons:
- () Allows you to change the position of layout items
- () 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
- () Allows the user to enter (or change) text
- () It is a list of options from which the user can choose, and it is possible for the user to include an item
- () It is a list of options from which the user can choose, and it is not possible for the user to include an item
- () Used to create a selection with multiple options
- () It allows to select mutually exclusive options, which will return the values True or False E.g. Yes or No
- () 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
- () Used to group controls that can work together or have common factors Widely used to group option buttons
- () Adds a button that can execute a code when clicked
- () Adds tabs that can contain the control sets, but different tabs will not have different controls
- () Adds tabs that can contain the control sets, and different tabs may have different controls
- () It is used to increment or decrement a value shown by another control. This increment can be previously defined
- () Similar to the scrollbar, it also serves to increase or decrease values, however with the possibility of "dragging"
- () Provides the ability to display an external image on the UserForm
- () 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.
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.
© 2024 SuperExcelVBA | ABOUT