Excel Developer Tip


Return to The Spreadsheet Page

Excel page

Tip archives

A Color Picker Dialog Box

This tip demonstrates a technique to display a dialog box that allows the user to select a color.

How it works

The example file contains the following:

  • A UserForm (UserForm1) that contains a dialog box with 56 buttons.
  • A Class Module (Class1) that defines a ColorButton Class. This is similar to the method used in another tip.
  • A VBA module (Module1) that contains a function (GetAColor).
  • Two example subroutines that demonstrate the GetAColor function.

The GetAColor function sets up the dialog box and display it (see the figure below). The function returns the color value of the selected button. If the user clicks Cancel, the GetAColor function returns False. As the user moves the mouse pointer over the color buttons, the Color Sample image displays the color.

Using the function

To use the GetAColor function in your own workbooks, export UserForm1, Module1, and Class1, and then import them into your workbook. Write your own subroutine that calls the GetAColor function.