To enable social distancing we've completely remodelled our classroom training, launched a full range of live online courses and now provide online training-cum-consultancy.
Drawing UserForms in the VBA code editor
Part four 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).

  1. An Introduction to UserForms in VBA
  2. Creating and Using UserForms in VBA
  3. The Properties Window
  4. Selecting Forms and Controls (this blog)
  5. Formatting Forms and Controls
  6. Grouping, Aligning, Sizing, Spacing and Arranging
  7. Controlling How Form Keys Work

This blog is part of our Excel VBA tutorial series.  We also run training classes in Excel and courses in VBA.

Posted by Andy Brown on 28 February 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Selecting Forms and Controls

To format any controls on a form, you first need to know how to select it/them.  We'll look first at selecting one control, then at how to select lots of controls at the same time (the next part of this blog will then show how to format controls and forms).

Selecting a Single Control

To change the format of a single control, click on it to select it and use the Properties window:

Control properties menu

Right-click on any control to show its properties, as shown here, if they're not already visible (as already mentioned, you can also press F4 at any time to bring up the Properties window).


Alternatively, you can select a control in the Properties window itself:

Properties window - control dropdown

Click on the drop arrow shown to choose the control whose properties you want to change.


Selecting Multiple Controls

There are several ways you can select lots of controls at the same time.  The easiest way is probably with the mouse button:

Click and drag selection

Click and drag on the form to draw a rectangle, making sure that you start on a blank part of the form. Any control that this rectangle touches or encloses will be selected. This example would select all 3 controls.


Alternatively, you could use the SHIFT or CTRL keys:

Selecting using keys

In this example, if you click on the OK button as shown:


Alternatively, you could press CTRL + A to select every control on the form in one go.

The Dominant Control

If you select multiple controls, one (and only one) of them will have white handles surrounding it; all of the others have black ones.  The one with the white handles is called the dominant control:

Controls with white and black handles

Here the label containing Name: is the dominant control.  If you have a number of controls selected, you can click on any one of them to make that one the new dominant control among those selected.


What this means is that if you choose to align or size the selected controls (as shown later in this blog), they will do be aligned or size by reference to the dominant control:

Aligned controls

The results of aligning the controls shown above by their left edges.  Everything lines up to the red line shown, since that is the left edge of the dominant control.


Selecting a Whole Form 

If you want to change properties for a form (such as its name), you need to select it:

Selecting a form with mouse

Click anywhere on a form apart from on one of its controls to select it, as shown here.



Now that you know how to select a form or its controls, it's time to look at how to format it/them.


This blog has 0 threads Add post