Excel 2010 Bible

(National Geographic (Little) Kids) #1

Part VI: Programming Excel with VBA


852


Tip
The VB Editor provides several useful commands to help you size and align the controls. For example, you can
make a group of selected controls the same size, or move them so they are all aligned to the left. Select the
controls that you want to work with and then choose a command from the Format menu. These commands are
fairly self-explanatory, and the Help system has complete details. n


Testing the UserForm

At this point, the UserForm has all the necessary controls. What’s missing is a way to display the
form. This section explains how to write a VBA procedure to display the UserForm.


  1. Make sure that the VB Editor window is activated.

  2. Insert a module by choosing Insert ➪ Module.

  3. In the empty module, enter the following code:


Sub ShowUserForm()
UserForm1.Show
End Sub


  1. Choose Run ➪ Sub/UserForm (or press F5).


The Excel window is then activated, and the new UserForm is displayed, as shown in Figure
41.11. The OptionButton controls work, but clicking the OK and Cancel buttons has no effect.
These two buttons need to have event-handler procedures. Click the Close button in the title bar
to dismiss the UserForm.

FIGURE 41.11

Displaying the UserForm.

Free download pdf