Vba button control in Excel
Button control is used to perform some action on the click of the button.
Button controls are the most used control in any GUI, as without it, the GUI will be meaningless.
A Buttton control can display both Text and Images.
Most of the applications now use images instead of plain text inside the button to give a visual appeal to the end user.
VBA Button Properties
This property is used to set the text to be displayed in the button control.
If the text exceeds the width of the control, then it is automatically wrapped.
This property is used to set the name of the button.
This name is used in the program to refer to the button for any action.
This property takes a binary value, either True or False.
This property is used to tell the program whether to resize the button accordingly.
This property is used to set the color of the button control.
This property is used to set the image to be displayed in the button control.
Apart from properties, there are various events associated with the button control.
But, VBA Click event is the one that is almost always used.
The following illustrates the click event.
The code within this event will be executed whenever the button is clicked.
The following example illustrates this:
- Private Sub CommandButton1_Click()
- MsgBox "I am Clicked!!"
- End Sub