Creating custom dialog boxes

Anyone who has used a personal computer for any length of time is undoubtedly familiar with dialog boxes. Consequently, custom Excel dialog boxes can play a major role in the user interfaces that you design for your applications. Figure 6-2 shows an example of a custom dialog box.

Create Workbook Contents Sheet

This utility inserts a worksheet that functions pjri

as a table of contents for the workbook. ^

Style

Create hyperlinks

Create buttons and macros

Name for contents sheet:

Workbook Contents

.ocation in the workbook:

First sheel r

Cancel

Number of columns: ,

1 column ^ |

OK |

Figure 6-2: A dialog box created with Excel's UserForm feature.

Figure 6-2: A dialog box created with Excel's UserForm feature.

A custom dialog box is known as a UserForm. A UserForm can solicit user input, get a user's options or preferences, and direct the flow of your entire application. You create and edit UserForms in the VBE. The elements that make up a UserForm (buttons, drop-down lists, check boxes, and so on) are called controls - more specifically, ActiveX controls. Excel provides a standard assortment of ActiveX controls, and you can also incorporate third-party controls.

After adding a control to a dialog box, you can link it to a worksheet cell so that it doesn't require any macros (except a simple macro to display the dialog box). Linking a control to a cell is easy, but it's not always the best way to get user input from a dialog box. Most of the time, you want to develop VBA macros that work with your custom dialog boxes.

CROSS- I cover UserForms in detail in Part IV.

REFERENCE

Was this article helpful?

0 0

Responses

Post a comment