Common properties

Although each control has its own unique set of properties, many controls have some common properties. For example, every control has a Name property and properties that determine its size and position (Height, Width, Left, and Right).

If you're going to manipulate a control by using VBA, it's an excellent idea to provide a meaningful name for the control. For example, the first OptionButton that you add to a UserForm has a default name of OptionButton1. You refer to this object in your code with a statement such as

OptionButton1.Value = True

But if you give the OptionButton a more meaningful name (such as obLandscape), you can use a statement such as obLandscape.Value = True

Many people find it helpful to use a name that also identifies the type of object. In the preceding example, I use ob as the prefix to identify the fact that this control is an OptionButton.

You can adjust the properties of several controls at once. For example, you might have several OptionButtons that you want left-aligned. You can simply select all the OptionButtons and then change the Left property in the Properties box. All the selected controls will then take on that new Left property value.

0 0

Post a comment