×

ActiveX Controls

ActiveX Controls

ActiveX Controls are one of the most used Excel Controls to automate applications with Excel VBA. It has the same controls, unlike Form Controls (Command Button, combo box, checkbox, etc.), but it supports more features and usability to perform multiple operations in the Excel sheet. For the same macro, ActiveX control and Form control will result in different outputs. In ActiveX control, the flow of the program is managed in the VBA editor window (where you can easily debug and run the code with ALT + F11). The user can add multiple ActiveX controls as per his requirement, whereas in Form Control the usability is limited.  These controls show up as objects that the user can use in the VBA code and thus used in complex scripts. You can use these controls for setting the layout and orientation for your excel sheet, fetching out the commonly used data, customizing the data, etc.,

Advantages of ActiveX Control

  • It is customizable and can be easily created.
  • ActiveX Control allows flexible design and is used to advanced scripts.
  • You can easily write up the code in VBA Editor and assign that code to your ActiveX control.
  • It is loaded into the memory separately. Hence, the program will run smoothly.
  • The user can access the flow of the control programmatically.
  • In this, the user can activate multiple controls.
  • ActiveX controls are used in day to day business activities and save a lot of time.

Disadvantages of ActiveX Control

  • These controls only work for Windows, and it is not supported in MAC. Thus, many users avoid them to use.
  • They are not used for basic and simple scripts.
  • By default, many computers don’t trust ActiveX controls and disable them. In that case, the user needs to add the trust center manually.

ActiveX controls are added in the Excel sheet while enabling the design mode. Once everything is set and, the programming is done, disable the design mode to activate the ActiveX control. The following steps are used to activate ActiveX Controls:

  1. Go to the Developer Tab. Click on insert under the Controls section.
ActiveX Controls
  • From the form control and ActiveX control, choose the required control. Unlike here, we have chosen the command button.
ActiveX Controls
  • Make sure the design mode is enabled. Drag the control (command button) to the excel sheet and place is appropriately as per the excel layout.
ActiveX Controls
  • You can rename the ActiveX control by right-clicking on the control and selecting the properties option. The properties dialog box appears on the left side of the sheet. Under the caption option set the control name. You can even change or enable the other properties unlike, font, BackColor, ForeColor, locked, visible, etc., for the control.
ActiveX Controls
ActiveX Controls
  • Double click on the control or right-click on the control and select the view code option. View code will direct you to the VBA Editor window where you can write the code to implement an action whenever the user clicks on the control. Write your code in between the sub and end sub procedure.
ActiveX Controls
  • Below we have written a code to change the font color for the selected data to Red.

Private Sub CommandButton1_Click()

Selection.Font.Color = vbRed

End Sub

ActiveX Controls
  • Come back again to the excel sheet and disable the design mode such as the control can become clickable.
ActiveX Controls
  • Select the text and click on the ActiveX Command Button.
ActiveX Controls
  • You will notice that the font color has changed from black to Red.
ActiveX Controls

Related Topics

Excel VBA DateValue Function

The DateValue function in VBA returns a VBA Date from the given String representation of a date wherein the time information is ignored. It is unable to interpret dates that include the...

1 minute read.

VBA Subscript out of Range

What is Subscript out of Range? The VBA Subscript out of Range error (which is also called as Run-Time Error 9) mostly triggers when the user selects any cell, sheet, or workbook which does...

5 minutes read.

Declaring a Variable in VBA

Declaring a Variable A variable is broadly described as a storage location combined with a name and representing a specific value. Declaring a variable is instructing the computer to reserve space...

2 minutes read.

Excel VBA Exp Function

VBA Exp Function: The Exp function in VBA returns the value of the exponential function ex (mathematical constant ‘e’ raised to specified power) for the given value of x. Syntax Exp (Number) Parameter Number (required) –This parameter represents...

1 minute read.

Excel VBA Conditional Statement

Conditional Statement in VBA Excel Conditional Statements in Excel VBA are one of the most powerful and useful features in programming, this will give you to perform comparisons to decide or...

2 minutes read.

Excel VBA Str Function

VBA Str Function: The Str function in VBA converts the given number into a string representation of that number. Syntax Str (Number) Parameter Number (required) – This parameter represents the numeric value that you want...

1 minute read.

Excel VBA String Function

The String function in VBA creates a String, consisting of several repeated characters. Syntax String (Number, Character) Parameter Number (required) – This parameter represents the number of characters in the returned String. Character (required) – This parameter...

1 minute read.

VBA runtime error 1004

What is 1004 error?  VBA 1004 Error, also known as object-defined or application-defined, is a runtime error in VBA, usually, if the specified range does not exist in the worksheet or if the Application...

6 minutes read.

Excel VBA IsArray Function

VBA IsArray Function: The IsArray function in VBA returns a Boolean, showing whether the given variable is an Array or not. Syntax IsArray (VarName) Parameter VarName (required)- This parameter represents the variable that you want...

1 minute read.

VBA Regex

What is a Regex? Regex stands for Regular Expression is basically a pattern matching strings within another string. They are supported in many languages, including .net, C++, Python, etc. They are...

5 minutes read.

Excel VBA Left Function

VBA Left Function: The Left function in VBA returns a substring from the start of the specified string. Syntax Left (Str, Length) Parameter Str (required) – This parameter represents the string that you want to extract...

1 minute read.

Excel VBA : With End-with Constructs

With End-with Constructs The With-End With construct enables the user to perform multiple operations on a single object. If you are going to perform several different actions on the same object and typing the same...

4 minutes read.

Excel VBA StrConv Function

The StrConv function in VBA converts a string into a specified format. Syntax StrConv (String, Conversion, [LocaleID]) Parameter String (required) – This parameter represents the string to be converted. Conversion (required) – This parameter specifies the type of conversion. It can...

1 minute read.

Procedures in VBA

Procedures in VBA A procedure is a block of statements or units of computer code that performs some action. It is enclosed with a declaration statement, and its primary purpose is to carry out...

3 minutes read.

Userform Events

What are Events? Anything you do in to trigger an excel file is an event (an action). Example: If you want a greeting message ‘Good Day’ whenever an excel file is...

7 minutes read.

Excel VBA: IF THEN Statement

VBA Excel: IF THEN StatementThis conditional statement enables you to check one condition and on the basis of that then run one or multiple statements if the condition holds. If...

1 minute read.

VBA Option Explicit

VBA Option Explicit The Option Explicit in VBA is used to declare the variables at the top of your macro code. It is the most secure and easy option to maintain your variables....

5 minutes read.

Introduction to Visual Basic Editor Window

How to enable the Developer Ribbon Tab? In order to work with VBA, users need to make a small change in Excel to display a new tab (Developer) at the top of the...

5 minutes read.

Excel VBA RTrim Function

VBA RTrim Function: The Rtrim function in VBA removes the leading spaces from the text in the specified string. Syntax RTrim (String) Parameter String (required) – This parameter represents the string from which you want...

1 minute read.

Excel VBA FormatCurrency Function

VBA FormatCurrency Function: The FormatCurrency function in VBA is used to apply a currency format to a numeric expression and returns the result as a string. Syntax FormatCurrency (Expression, [NumDigitsAfterDecimal], [IncludeLeadingDigit], [UseParensForNegativeNumbers], [GroupDigits]) Parameter Expression (required)...

2 minutes read.