CHAPTER 14Looking at UserForm Examples

Creating a UserForm “Menu”

Sometimes, you might want to use a UserForm as a type of menu. In other words, the UserForm presents some options, and the user makes a choice. This section presents two ways to do this: by using command buttons and by using a list box.

Using CommandButtons in a UserForm

Figure 14.1 shows an example of a UserForm that uses command buttons as a simple menu.

Screenshot of the dialog box that uses a dialog box as a menu.

FIGURE 14.1 This dialog box uses command buttons as a menu.

Setting up this sort of UserForm is easy, and the code behind the UserForm is straightforward. Each command button has its own procedure for its Click event. For example, the following procedure is executed when CommandButton1 is clicked:

Private Sub CommandButton1_Click()
    Unload Me
End Sub 

This procedure hides the UserForm, runs ...

Get Excel 2019 Power Programming with VBA now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.