An Overview of Creating UserForms in Excel 2016 VBA
In VBA, the official name for an Excel dialog box is a UserForm. But a UserForm is really an object that contains what’s commonly known as a dialog box. This distinction isn’t important, so many programmers use these terms interchangeably.
When creating a UserForm, you usually take the following general steps:
-
Determine how the dialog box will be used and at what point it will be displayed in your VBA macro.
-
Press Alt+F11 to activate the VBE and insert a new UserForm object.
A UserForm object holds a single UserForm.
-
Add controls to the UserForm.
Controls include items such as text boxes, buttons, check boxes, and list boxes.
-
Use the Properties window to modify the properties for the controls or for the UserForm itself.
-
Write event-handler procedures for the controls (for example, a macro that executes when the user clicks a button in the dialog box).
These procedures are stored in the Code window for the UserForm object.
-
Write a procedure (stored in a VBA module) that displays the dialog box to the user.