Microsoft Office Tutorials and References
In Depth Information
Creating a UserForm: An Example
11.
Add another CommandButton control and adjust the properties as follows:
Property
Value
Caption
Close
Cancel
True
Name
CloseButton
TabIndex
4
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
control.
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 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.
5.
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
UserForm.
 
Search JabSto ::




Custom Search