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

1.Text Property

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.

2.Name Property

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.

3.Autosize

This property takes a binary value, either True or False.

This property is used to tell the program whether to resize the button accordingly.

4.BackColor Property:

This property is used to set the color of the button control.

5.Image Property

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.

excel vba button control

The code within this event will be executed whenever the button is clicked.

The following example illustrates this:

  1. Private Sub CommandButton1_Click()
  2. MsgBox "I am Clicked!!"
  3. End Sub

excel vba button control

 

You can find similar Excel Questions and Answer hereunder

1) How to control forms in Excel VBA

2) Here an explanation about the options in button control in Excel VBA

3) Here an explanation about frames and how to control frames in Excel VBA

4) Here an explanation about combo boxes and interfacing with your user in Excel VBA

5) Here an explanation about spin button and how to control it using VBA

6) Here an explanation about checkbox and how to control checkboxes in Excel VBA

7) Here an explanation about list box and how to control list boxes in Excel VBA

8) Here an explanation about label controls in the various forms and controls using VBA

9) What are ActiveX controls in VBA. Here some good explanations

10) Here an explanation about text box and how to control text boxes in Excel VBA

 

Here the previous and next chapter