Defining Colors for Controls, UserForms, and Projects


Many UserForm controls, and the UserForm itself, can exhibit colors—for backgrounds, foregrounds, and for borders. MDUF offers a number of alternatives for defining these colors.

Specifying colors for controls of a UserForm

In the MDUF Ribbon group “This FormSpec” is a menu button with a label that reads “Set/Clear Color”. The items of this menu enable entry of codes for the color properties of controls and for the UserForm itself. This menu button contains six items at the first level. Three of the items are submenus.

The Color Picker oDialogBox
The Color Picker oDialogBox

Some of the commands on this menu or its submenus insert color specifications in various places on the FormSpec worksheet. Others clear data from those same places. For example, the command Set Selected Cells… opens a Colors dialog. An example of the dialog is shown here. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into any cells in the selection that are intended to hold color specifications. If the selection includes cells that aren’t intended to hold color specifications, those cells are ignored.

Changing a color

Most controls, and the UserForm itself, have a forecolor and a backcolor. Some controls also have a bordercolor. MDUF enables independent specification of all these color properties, as do the applications of Microsoft Office.

But MDUF also enables more systematic color specification. For example, you can specify the forecolor, backcolor, or bordercolor of all controls, or the UserForm itself, in an entire project, including all its UserForms, with a single command.

Setting default colors

An MDUF Project workbook supports defining default colors for the project’s UserForms or for the controls they carry. For example, every FormSpec worksheet in the MDUF Project workbook contains three cells named, respectively, Ctrl.ForeColor, Ctrl.BackColor, and Ctrl.BorderColor. MDUF uses these colors for any of the UserForm’s controls that don’t specify their own values for these colors. The FormSpec worksheet also provides a means of specifying any of these three colors for individual controls that are capable of having any of these colors specified. However, if you don’t specify a control’s forecolor, for example, then MDUF uses the contents of Ctrl.ForeColor when it generates the UserForm. Thus, Ctrl.ForeColor, Ctrl.BackColor, and Ctrl.BorderColor act as color defaults for the controls of the UserForm specified by that FormSpec worksheet and which have the capability of having any of these colors specified.

In addition to per-UserForm color defaults just described, there are per-project color defaults. Each MDUF Project workbook contains a Project worksheet. The Project worksheet contains three named cells Ctrl.ForeColor, Ctrl.BackColor, and Ctrl.BorderColor. For example, when MDUF generates a UserForm, and it requires a backcolor specification for a control, it looks in the control’s specification first. If the color isn’t specified there, it checks Ctrl.BackColor for that FormSpec worksheet and uses it if it has been specified. If Ctrl.BackColor hasn’t been specified, MDUF checks Ctrl.BackColor on the Project worksheet, and uses it if it has been specified. If the project’s Ctrl.BackColor hasn’t been specified, MDUF uses Excel’s default.

In summary, the default color scheme priorities are indicated below for each color type. For concreteness, the priorities below are for forecolor:

  • Forecolor of the Control
  • Ctrl.Forecolor of the FormSpec worksheet
  • Ctrl.Forecolor of the Project worksheet

Backcolor and Forecolor are analogous. This default scheme saves time and trouble not only when first specifying a UserForm but also when maintaining it. And it reduces the effort required to generate or maintain FormSpec worksheets programmatically.

Below is a summary of the color commands in the MDUF Ribbon menu This FormSpec>Set/Clear Color. These commands execute operations on the active sheet. They are available whenever the active sheet is a FormSpec worksheet.

In the descriptions below, Xcolor stands for Forecolor, Backcolor, or Bordercolor.

This FormSpec>Set/Clear Color>Set Selected Cells…

Opens a Colors dialog. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into any cells in the selection that are intended to hold color specifications. If the selection includes cells that aren’t intended to hold color specifications, those cells are ignored.

This FormSpec>Set/Clear Color>Clear Selected Cells

Clears the contents of all cells in the selection that are intended to hold color data. Use this to clear cells that are intended to hold color specifications.

This FormSpec>Set/Clear Color>XColor>Set for All Controls…

Opens a Colors dialog. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into the Xcolor cell of all control records that have non-empty name cells.

This FormSpec>Set/Clear Color>XColor>Clear from All Controls…

Clears the contents of the Xcolor cell of all control records that have non-empty name cells.

This FormSpec>Set/Clear Color>XColor>Set Default for All Controls…

Opens a Colors dialog. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into the cell named Ctrl.Xcolor, which acts as a default for any controls that don’t specify their Xcolor.

This FormSpec>Set/Clear Color>XColor>Clear Default from All Controls…

Clears the contents the cell named Ctrl.Xcolor.

This FormSpec>Set/Clear Color>Clear All Controls Color

For the active sheet, clears the contents of all cells that are intended to hold color specifications for specific kinds of controls. 

Specifying colors for Projects

The “This Form” and a portion of the “This Project” groups of the MDUF ribbon tab.

The figure above illustrates two groups of the MDUF ribbon tab, namely, This FormSpec and This Project. In the section above, we discussed the commands on the menu button “Set/Clear Color” of the group “This Form.” In this section, we discuss the commands on the menu button “Set/Clear Color” of the group “This Project.” In the table below, Xcolor stands for Forecolor, Backcolor, or Bordercolor.

This Project>Set/Clear Color>XColor>Set for All Controls in Project…

Opens a Colors dialog. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into the Xcolor cell of every control on every FormSpec worksheet in the project, provided that control can specify that kind of color. (Some controls don’t support Xcolor. For example, the Image control doesn’t support backcolor)

This Project>Set/Clear Color>XColor>Clear from All Controls in Project

Clears the contents of the Xcolor cell of every control on every FormSpec worksheet in the project.

This Project>Set/Clear Color>XColor>Set for All FormSpecs in Project…

Opens a Colors dialog. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into the cell named Form.Xcolor on every FormSpec worksheet.

This Project>Set/Clear Color>XColor>Clear from All FormSpecs in Project

Clears the contents the cell named Form.Xcolor on every FormSpec worksheet.

This Project>Set/Clear Color>XColor>Set Default for Controls in Project…

Opens a Colors dialog. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into the cell named Ctrl.Xcolor on the Project worksheet, which acts as a default for any UserForms that don’t specify their Xcolor in the cell named Ctrl.Xcolor on their FormSpec worksheets.

This Project>Set/Clear Color>XColor>Clear Default from Controls in Project

Clears the contents the cell named Ctrl.Xcolor on the Project worksheet.

This Project>Set/Clear Color>XColor>Set Default for FormSpecs in Project…

Opens a Colors oDialogBox. If you choose a color and click OK, MDUF inserts the Hex code for the chosen color into the cell named Form.Xcolor on the Project worksheet, which acts as a default for any UserForms that don’t specify their Xcolor in the cell named Form.Xcolor on their FormSpec worksheets.

This Project>Set/Clear Color>XColor>Clear Default from FormSpecs in Project

Clears the contents the cell named Form.Xcolor on the Project worksheet.

This Project>Set/Clear Color>Clear Project Colors

Clears the contents of the cells named Form.ForeColor, Form.BackColor, Form.BorderColor, Ctrl.ForeColor, Ctrl.BackColor, and Ctrl.BorderColor on the Project worksheet of the Project workbook.

This Project>Set/Clear Color>Clear All Controls Color

Clears any cells in control records containing color specifications. This is useful when you’ve specified colors at the control level, and you want to shift to specifying them at a UserForm level or Project level.