562 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Drawing UserForms in the VBA code editor
Part two of a seven-part series of blogs
Learn how to create your own custom dialog boxes in VBA, using UserForms. This is the first part of a three-part series (the other parts are on Writing Code for UserForms and Creating Advanced Controls).
It's easy enough to create a user form in VBA - within the code editor, just right-click and choose to add a user form:
Right-click in a project/workbook and choose the option shown to insert a user form.
You'll be shown a rectangular form, which you can resize using the bottom right corner:
Click and drag on the bottom right corner to resize a user form - it will always appear at the top left corner of the code editor window.
Just like macros, a user form is stored as part of a workbook, rather than in a separate file.
The things that you add to a user form are called controls. The following simple form has 3 controls:
This form has 1 label, 1 textbox and 1 command button.
The following drinks order form has more than 10 controls:
This relatively simple form contains:
A later blog in this series shows how to add some of the more esoteric controls - for now, we'll stick to general principles.
You can draw any control on a form using the Toolbox:
The form Toolbox - the simplest controls are shown at the top left.
If you can't see your Toolbox window when you have a form open, try clicking on the Toolbox tool:
Click on the tool shown to display the Toolbox, if it's gone AWOL.
Once you've chosen your control tool, you can click and drag on your form where you want it to go:
Here the mouse pointer shows that you are drawing a Label control.
It's often easier just to click where you want a control to go, and Excel (or any other application) will draw it with a standard size and shape.
Having learnt how to draw controls, let's move on to how to show their properties.
|Parts of this blog|
25 Aytoun Street