18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using UserForm Controls in a Worksheet 42<br />

FIGURE 42.4<br />

Double-clicking a control in design mode activates the Visual Basic Editor and enters an empty event-handler procedure.<br />

4. Double-click the button.<br />

The VB Editor window is activated, and an empty Sub procedure is created.<br />

5. Enter the following VBA statement before the End Sub statement:<br />

MsgBox “Hello. You clicked the command button.”<br />

6. Press Alt+F11 to return to Excel.<br />

7. If you want, adjust any other properties for the CommandButton using the Properties window.<br />

(Click Developer ➪ Controls ➪ Properties if the Properties window doesn’t appear.)<br />

8. Click the Design Mode button in the Developer ➪ Controls section to exit design mode.<br />

After performing the preceding steps, click the CommandButton to display the message box.<br />

NOTE<br />

You must enter the VBA code manually. You can’t create macros for controls using the VBA<br />

macro recorder.<br />

Reviewing the Available ActiveX Controls<br />

The sections that follow describe the ActiveX controls that are available for use in your worksheets.<br />

ON the CD-ROM<br />

The companion CD-ROM contains a file that includes examples of all the ActiveX controls.<br />

This file is named worksheet controls.xlsm.<br />

CheckBox control<br />

A CheckBox control is useful for getting a binary choice: yes or no, true or false, on or off, and so on.<br />

The following is a description of the most useful properties of a CheckBox control:<br />

n<br />

n<br />

Accelerator: A letter that enables the user to change the value of the control by using the keyboard.<br />

For example, if the accelerator is A, pressing Alt+A changes the value of the CheckBox<br />

control. The accelerator letter is underlined in the Caption of the control.<br />

LinkedCell: The worksheet cell that’s linked to the CheckBox. The cell displays TRUE if the control<br />

is checked or FALSE if the control is not checked.<br />

739

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!