Page 222 - Excel Data Analysis
P. 222
11 537547 Ch10.qxd 3/4/03 12:03 PM Page 208
EXCEL DATA ANALYSIS
CAPTURE INPUT FROM
A CUSTOM DIALOG BOX
ou typically use dialog boxes in Excel to gather input each time a user clicks a control. To generate the code that
from the user. You can make the input you capture interacts with the UserForm, you must create procedures
Y from a user anything from determining which button that execute when specific events occur.
the user pressed to what values the user typed. You can Each UserForm that you create has two elements: the
then capture the user input and return the appropriate graphical layout window and a code window. The graphical
responses by using the UserForm events. Data analysts may layout window is where you add controls that appear in the
find this useful if they want to walk a user through a dialog box. See the section "Create a Custom Dialog Box"
particular calculation or worksheet. For example, when the for more information on designing custom dialog boxes.
user clicks an OK CommandButton control, you use a Each UserForm also has a code window that contains all
CommandButton_Click subroutine to indicate what steps UserForm-specific code and that you use to create the
to perform.
event procedures for each control.
Excel considers every user interaction that occurs in a dialog By default, the Visual Basic Editor creates a Click event for
box as an event, such as scrolling through a list of items, a control when you click it. If a Click event already exists,
selecting an OK button, or typing text in a text box. Each the Visual Basic Editor simply displays the code window.
UserForm control has several different events that you can
capture. The most common event is Click, which occurs
CAPTURE INPUT FROM A CUSTOM DIALOG BOX
⁄ Create a UserForm in the ¤ In the Toolbox, click the ‹ Click the Command ■ The text on the
appropriate project. ListBox control and drag it to button and drag it to the CommandButton changes
the UserForm. UserForm. to reflect the value of the
Note: See the section "Create a caption property.
Custom Dialog Box" for information › In the Properties window,
on creating UserForms. type text for the Caption ˇ Double-click the
property value. CommandButton.
208