Microsoft Office Tutorials and References
In Depth Information
Creating a UserForm: An Example
Add another CommandButton control and adjust the properties as follows:
When you’re creating several controls that are similar, you may find it easier to copy an
existing control rather than create a new one. To copy a control, press Ctrl while you
drag the control to make a new copy of it. Then adjust the properties on the copied
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:
(Alt+F11 is the shortcut key combination.)
Choose Developer➜Controls➜Insert and click CommandButton from the ActiveX
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
Double-click the CommandButton.
This step 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.
Enter a single statement in the CommandButton1_Click procedure (see Figure 13-10).
This short procedure uses the Show method of an object ( UserForm1 ) to display the