VBA for Excel 2007 tutorial-Controls


Controls

A form can be said as a container of other controls. The most commonly used controls are Label, TextBox, CommandButton, OptionButton, CheckBox, ComboBox, ListBox, and Image. You can show the these controls by clicking on the Toolbox in the ribbon menu.


VBA for Excel: Toolbox to display a list of controls

VBA for Excel: commonly used controls  

-Label
is a control in which icons or uneditable text is displayed.

-Textbox is a control in which the user inputs data from the keyboard. This area also can display information.

-CommandButton is a control that triggers an event when clicked.

-OptionButton is used to select one of multiple choices.

-CheckBox is used to select multiple values or choices.

-ComboBox is a drop-down list of items from which the user can make a selection either by clicking an item in the list or by typing into a box.

-ListBox is a control in which a list of items is displayed. The user can make a

selection from the list by clicking on any item. Multiple elements can be selected.

-Image is a control that allows the user to display an image.




Label: common properties
 and events

Description
 

Common properties
 Font
Caption
TextAlign

 
The font of text to be displayed on the label
The text of the label
The alignment of the text(left, center, right)

TextBox: common properties and events

Description
 

Common properties
Font
Text
Multiline
 

 
The font of text to be displayed on the textbox
The text of the textbox
If true, the textbox can accept multi lines of text. If false, the textbox accept a single line of text

Common events
Keypress
Change

 
This event is triggered when the keyboard is pressed.
This event is triggered when the text of the textbox is changed.

ButtonButton: common properties and events

Description
 

Common properties
Caption

 
The text displayed on the button
 

Common events
Click

 
This event is triggered when the button is clicked.
 
OptionButton: common properties and events Description
Common properties

Caption
Value

Common events

Click


The text displayed on the right of the option button
True or False. True value indicates that the option is selected, otherwise the option is not selected.


The event is triggered when the option is clicked

CheckBox: common properties and events

Description

Common properties

Caption
Value

Common events
Change
 


 

The text displayed on the right of the checkbox


True or False. True value indicates that the checkbox is checked, otherwise it is unchecked.
 
This event is triggered when the checkbox is checked or unchecked.

ComboBox: common properties and events

Description

Common properties
Value
List

 
The value of the combo box

Contains all items of the combo box


Common events
Change

 
This event is triggered when an item of the combo box is selected.

ListBox: common properties and events

 

Common properties
Value
List

 
The value of the list box

Contains all items of the list box


Common events
Change

 
This event is triggered when an item of the listbox is selected.
   

Image: common properties and events

Description

Common properties
Picture
PictureSizeMode

 
Set the picture to display.
Controls image sizing and positioning (Values: 0-fmPictureSizeModeClip, 1-frmPictureSizeModeStretch, 3-PictureSizeModeZoom.

Common events
Click

 
This event is triggered when the image is clicked.
 

Example




Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.