Microsoft Office Tutorials and References
In Depth Information
14.5 Excel's Standard Controls
There are several reasons why it is better to place the sorting code in a separate procedure. This
code modularity makes it easier to:
Use the code in other locations in the application
Move the code to other applications
Find and repair bugs in the code
Make improvements or additions to the code
Just plain read the code
Once the sorting procedure is complete, we can add the following code to the Click event:
Private Sub cmdSort_Click()
If MsgBox("Sort currently selected columns?", _
vbQuestion + vbYesNo) = vbYes Then SortColumns
End Sub
Incidentally, the Click event for the Cancel button is often just the following:
Private Sub cmdCancel_Click()
Unload Me
End Sub
All this does is unload the form.
While on the subject of unloading a form, it is important to understand the distinction between
unloading a form and hiding a form. We can hide a form by setting the form's Visible property to
False . This makes the form invisible, but it still consumes resources, such as memory. When we
unload a form, it no longer consumes resources. (Well, this is not quite true. We need to not only
unload the form, but also to set any variables that reference the form to Nothing .)
14.5 Excel's Standard Controls
Excel has two types of controls. Figure 14-3 s hows two toolboxes, each of which provides access
to one type of control. (Below each toolbox is a control created using that toolbox.)
Figure 14-3. Control toolbars
Search JabSto ::

Custom Search