Page 220 - Excel Data Analysis
P. 220
11 537547 Ch10.qxd 3/4/03 12:03 PM Page 206
EXCEL DATA ANALYSIS
CALL A CUSTOM DIALOG
BOX FROM A MACRO
ou can call and display any custom dialog boxes that The default value of vbModal makes the dialog box modal,
are part of the same project as your macro code. You which means that you must either close or hide the dialog
Y use custom dialog boxes to simplify the data box before selecting any other options in Excel. When a
collection or data analysis process because dialog boxes add modal dialog box opens, Excel passes all control to that
a graphical user interface; they let users click buttons to dialog box; users can only select options in it, but not in any
indicate a specific selection or to input an appropriate value. other dialog box. A value of vbModeless means that
For example, you can have a dialog box open to request although the dialog box remains open until a user closes it,
values from the user to perform appropriate calculations a user can perform other program options.
within a worksheet. See the section "Create a Custom You can close a dialog box with the normal Close button, or
Dialog Box" for more information on custom dialog boxes.
you can close it within your macro using the Unload
To display a custom dialog box, you use the Show method method. Typically, all dialog boxes contain a Close or
of the UserForm object. This method has only one optional Cancel button to allow a user to close the dialog box. You
parameter, as shown in the following code: must use the Click event for these CommandButton
controls to create a procedure that calls the Unload
UserForm1.Show modal method. See the section "Capture Input from a Custom
Dialog Box" for more information about specifying code to
The modal parameter determines whether the UserForm run when a user clicks a button.
displays as a modal or modeless dialog box within Excel.
CALL A CUSTOM DIALOG BOX FROM A MACRO
InputForm
⁄ Create a UserForm in the Note: See the section "Create a ‹ Type the name of the › Press Enter.
appropriate project. Custom Dialog Box" for information macro to create.
on creating UserForms. ■ The VB Editor adds the
Note: See Chapter 9 for information End Sub statement.
¤ Click Insert ➪ Module. on creating macros.
206