Writing code to display the dialog box

Next, you add an ActiveX CommandButton to the worksheet. This button will execute a procedure that displays the UserForm. Here's how:

1. Activate Excel. (Alt+F11 is the shortcut key combination.)

2. Choose Developer Controls Insert and click CommandButton from the ActiveX Controls section.

3. Drag in the worksheet to create the button.

If you like, you can change the caption for the worksheet CommandButton. To do so, right-click the button and choose CommandButton Object

Edit from the shortcut menu. You can then edit the text that appears on the CommandButton. To change other properties of the object, right-click and choose Properties. Then make the changes in the Properties box.

4. Double-click the CommandButton.

This activates the VBE. More specifically, the code module for the worksheet will be displayed, with an empty event handler procedure for the worksheet's CommandButton.

5. Enter a single statement in the CommandButton1_Click procedure (see Figure 13-10). This short procedure uses the Show method of an object (UserFormi) to display the UserForm.

>" Hiciuwit y>hjj' bern ■ wlnini


Hijln ■ r>'-K-*n ¡L&JcQ



3 [b ffl* Btow ^iwt i-;-rmit

^ibug etn 2«ati ¿dulm htndbw grip

_ A


H A 4JJ ^


J 'j « Lni.CüJL




vj C*A

S3 j

C.-3 3 *1:

•J 1 i*"!»

3 Wirr»«L

1« 1


- <


Figure 13-10: The CommandButton1_Click procedure is executed when the button on the worksheet is clicked.

0 0

Post a comment