Open In App

ActiveX Control in Excel VBA

Last Updated : 29 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

When we are automating an excel sheet with VBA at that time when the user has a requirement for a more flexible design then it’s better to use ActiveX Controller. In Excel user has to add the ActiveX Controller manually and ActiveX Controls are used as objects in codes. There are the following types of ActiveX Controls that are important:

  • Text Box
  • List Box
  • Combo Box
  • Check Box

How to Create ActiveX Control in Excel VBA?

To do some changes in the excel sheet using ActiveX control we need to use the Command-click button for that we have to follow further steps

Step 1: Select the developer tab and click Insert drop-down list from the control box.

Clicking-control-box

 

Step 2: Choose the command button from ActiveX Controls Box.

Clicking-command-button

 

Step 3: Draw the command button in the excel sheet.

Drawing-command-button

 

Step 4: Right-click on the command button and select view code to write the VBA code.

Selecting-view-code

 

Step 5: When the user will click on Command Button they should get their respective values in the cell. So for that, we have to write codes in VBA.

Writing-code-in-vba

 

In the VBA code, we can write codes in different ways to get the action done by VBA on clicking the command button which we have discussed in the following 

Text Box

It is a type of ActiveX Controls which is used to fill the empty field with text which is useful for us to get the details of the input from the user such as name, year, department, date of birth, etc by the text of the box

Step 1: Select the Text Box from the ActiveX Controls box.

Selecting-text-box

 

Step 2: Draw the Text Box in the excel sheet and then right-click on the box to select view code.

Selecting-view-code

 

Step 3: Write a code in VBA to create a Text Box with a name so that it can be used to access the inputs given by a user.

Writing-code-in-vba

 

List Box

It helps us to fill a box with a list of values so that we can users can select any value from it for that we have to follow further steps.

Step 1: Select the List Box from the ActiveX Controls box.

selecting-list-box

 

Step 2: Draw the List Box in the excel sheet and then right-click on the box to select view code.

Selecting-view-code

 

Step 3: Write a code in VBA to add items to the list box.

Writing-code-in-vba

 

Combo Box

It is used to make a drop-down list where the user can select an item from the drop-down list for that we have to follow further steps.

Step 1: Select the Combo Box from the ActiveX Controls box.

selecting-combo-box

 

Step 2: Draw the Combo Box in the excel sheet and then right-click on the box to select the view code.

Selecting-view-code

 

Step 3: Write a code in VBA to add items to the combo box.

Writing-code-in-vba

 

Check Box

It is used to create a check box where a list of values is stored which gets visible upon selecting the check box for that we have to follow further steps.

Step 1: Select the Check Box from the ActiveX Controls box.

selecting-check-box

 

Step 2: Draw the Check Box in the excel sheet and then right-click on the box to select view code.

Selecting-view-code

 

Step 3: Write a code to display the value when a check box is marked.

Writing-code-in-vba

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads