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
Search our website
We also send out useful tips in a monthly email newsletter ...
Drawing UserForms in the VBA code editor Part six 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).
This blog is part of our Excel VBA tutorial series. We also run training classes in Excel and courses in VBA.
|
An earlier part of this blog showed how to select multiple controls at the same time, and explained that the one with the white borders is the dominant control (and what this means). This webpage shows how to align, distribute, center and otherwise arrange controls, and also how to group them together.
To align controls, select them and choose the right-mouse button options shown below:
Here the Name: label is the dominant control, so selecting Lefts as shown will align the selected controls to its left edge.
In the form below, the controls need distributing equally:
The control would look better equally spaced in this case.
To do this, select the controls as shown and then choose one of the menu options shown here:
The option shown is the one we want in this instance, but it's reasonably obvious what the others would do.
Note that in this case you would then have to do the same thing to the textboxes/combobox, to get them to align in the same way.
Here's how to get 2 or more controls to have the same size or width:
Select the controls, then right-click on one of them and choose the menu option shown here. The Drink combobox is the dominant control, so the other two selected controls will be resized to have the same width as this one.
When you've drawn part of a form, it's often useful to group its controls together so that they behave as a single control:
Here we want to group all of the controls in the frame together so that we can move them around as one.
One way to do this is to select all of the controls and group them together:
![]() |
![]() |
Group the controls like this ... | ... and they'll be selected as one. |
Even after grouping controls together, you can still format individual controls within the group separately, so you get the best of both worlds.
You can ungroup grouped controls in the same way:
Right-click on a grouped set of controls and choose to ungroup it as shown here.
An alternative way to group controls together is by creating a frame to hold them. First cut any controls you want to appear on the frame:
Select any controls you want to group together, and cut them to the clipboard.
Click on the Frame tool, and use it to draw a rectangle:
Click on this tool, and draw a rectangle for your frame.
You can now delete the title of the frame, and paste your controls on to it:
Delete the Frame1 title (it's the Caption property of the control) to make it look tidier, then paste the controls from the clipboard onto the frame (make sure you have it selected when you do this).
Result: wherever the frame goes, so too do any controls sitting on it:
When you move the frame, the controls on it move too.
You could always set the BorderStyle of the frame to frmBorderStyleNone to hide its border, if you don't want to see the rectangle.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.