Creating A Color Picker Dialog Box
A companion file is available: Click here to downloadThis 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.
- 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.
Search for Tips
Browse Tips by Category
Needs tips? Here are two books, with nothing but tips:
Contains more than 200 useful tips and tricks for Excel 2007 | Other Excel 2007 books | Amazon link: John Walkenbach's Favorite Excel 2007 Tips & Tricks