Additional Controls

UserForms are programmable containers for ActiveX controls. They enable you to build customized windows to serve as a user interface in any VBA application. UserForms are similar to other VBA objects in that they have properties, methods, and events that you use to control the appearance and behavior of your interface window; but the main function of a UserForm is to serve as a container for other ActiveX controls. UserForms are part of the VBA object library, and therefore, are available to use in all MS Office applications (Excel, Word, PowerPoint, and so on). In this chapter you will learn how to design UserForms using ActiveX controls for inclusion in your VBA programs.

In this chapter I will examine:

• The Option Button Control

• The Scroll Bar Control

• The Frame Control

• The RefEdit Control

• The MultiPage Control

• The List Box and Combo Box Controls

• Custom Data Types and Enumerations

Project: Blackjack

Blackjack is a standard on most computers. You can find numerous versions of this game in Windows, Java, and JavaScript. This chapter reproduces the game using VBA UserForms with Excel, which is something you probably have not seen before. Figure 6.1 shows the Blackjack game in the Excel application.

The Blackjack game.

The Blackjack game.

Advanced Userforms

DesiGNiNG Forms witH VBA

If you have previous programming experience in Visual Basic (even as a novice), then User-Forms (hereafter referred to as a VBA form or just form when used in the general sense) will be very familiar, because they will remind you of Visual Basic forms. If you have never used Visual Basic, then VBA forms will probably look just like another Window; however, VBA forms are not quite VB forms or regular windows because they don't have as many features. For example, there are no minimize and maximize buttons in the upper-right corner. Also, there are fewer properties and methods available for altering the appearance and behavior of the UserForm object. Nonetheless, VBA forms are invaluable for adding custom user interfaces to your applications.

Forms are included in VBA to allow programmers to build custom user interfaces with their office applications. Up to this point, input from the user via dialog boxes has been limited to InputBox() and MsgBox() functions. Because forms can be customized using a number of ActiveX controls, they greatly extend the ability of VBA programmers to collect user input.

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Post a comment