CommandBarControl
Methods, properties, and an event for managing custom controls on a CommandBar.
Methods
CommandBars(CommandBarId).Controls.Item()
Retrieves a single custom control by index so you can read or update its caption, or trigger a click.
-
Demonstration
Add a button

Delete a button

-
Syntax
expression.CommandBars(CommandBarId).Controls.Item(Index)expression: a document type application object.
-
Parameters
Parameter
Data type
Required
Description
Index
Number
Yes
The index of the custom control.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; // Delete the custom control after 6,000 milliseconds. setTimeout(() => { controlButton.Delete(); }, 6000); }
CommandBars(CommandBarId).Controls.Add(Type).Delete()
Deletes a custom control using the Delete() method.
-
Demonstration
Before deletion

After deletion

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).Delete()expression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and configure the caption. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; // Add a custom drop-down list and configure the caption. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; // Delete both controls after 6,000 milliseconds. setTimeout(() => { controlButton.Delete(); controlPopup.Delete(); }, 6000); }
CommandBars(CommandBarId).Controls.Add(Type).Execute()
Triggers a click on a custom control using the Execute() method. To detect when the control is clicked, use the CommandBars(CommandBarId).Controls.Add(Type).OnAction() event.
-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).Execute()expression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and set a click handler. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; controlButton.OnAction = () => console.log('Button clicked'); // Add a custom drop-down list and set a click handler. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; controlPopup.OnAction = () => console.log('Drop-down list clicked'); // Programmatically click both controls after 6,000 milliseconds. setTimeout(async () => { await controlButton.Execute(); await controlPopup.Execute(); }, 6000); }
CommandBars(CommandBarId).Controls.Add(Type).SetFocus()
Moves focus to a custom control using the SetFocus() method.
Demonstration

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).SetFocus()expression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and move focus to it. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; await controlButton.SetFocus(); // Add a custom drop-down list and move focus to it. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; await controlPopup.SetFocus(); }
Properties
The following table lists all configurable properties of a CommandBarControl item. Each property is described in detail in the sections below.
|
Property |
Data type |
Required |
Description |
|
Caption |
String |
Yes |
The label text displayed on the control. |
|
Enabled |
Boolean |
No |
Whether the control is interactive. Set to |
|
Picture |
String |
No |
The icon displayed on the control. Accepts a Base64-encoded image string. |
|
TooltipText |
String |
No |
The tooltip text shown when hovering over the control. |
|
Visible |
Boolean |
No |
Whether the control is visible. Set to |
CommandBars(CommandBarId).Controls.Add(Type).Caption
Sets the label text displayed on a custom control using the Caption property.
Demonstration

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).Captionexpression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and configure the caption. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; // Add a custom drop-down list and configure the caption. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; }
CommandBars(CommandBarId).Controls.Add(Type).Enabled
Disables a custom control using the Enabled property. Set Enabled to false to gray out the control and prevent interaction.
Demonstration. The button is grayed out.

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).Enabledexpression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and disable it. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; controlButton.Enabled = false; // Add a custom drop-down list and disable it. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; controlPopup.Enabled = false; }
CommandBars(CommandBarId).Controls.Add(Type).Picture
Sets an icon for a custom control using the Picture property. The value must be a Base64-encoded image string.
Demonstration

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).Pictureexpression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and set a Base64 icon. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; controlButton.Picture = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjM0Q0NzU3IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik04LjIxMyAxM0g2LjhsNi42MzYtNi42MzYtNC4yNDMtNC4yNDMtNy4wNyA3LjA3MUw1LjkyOCAxM0g0LjUxNUwxLjA2IDkuNTQ2YS41LjUgMCAwIDEgMC0uNzA3TDguODM5IDEuMDZhLjUuNSAwIDAgMSAuNzA3IDBsNC45NSA0Ljk1YS41LjUgMCAwIDEgMCAuNzA3TDguMjEzIDEzeiIgZmlsbC1ydWxlPSJub256ZXJvIi8+PHBhdGggZD0iTTQuNTM2IDYuMzY0bDQuOTUgNC45NS0uNzA3LjcwNy00Ljk1LTQuOTV6TTQuNTIxIDEzaDEwLjAzdjFINS40OTZ6Ii8+PC9nPjwvc3ZnPg=='; // Add a custom drop-down list and set a Base64 icon. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; controlPopup.Picture = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik03LjUgMnYyLjVINGEuNS41IDAgMCAwLS41LjV2MmEuNS41IDAgMCAwIC41LjVoOWEuNS41IDAgMCAwIC41LS41VjVhLjUuNSAwIDAgMC0uNS0uNUg5LjVWMmEuNS41IDAgMCAwLS41LS41SDhhLjUuNSAwIDAgMC0uNS41eiIgc3Ryb2tlPSIjM0Q0NzU3Ii8+PHBhdGggZmlsbD0iIzNENDc1NyIgZD0iTTEzIDdoMXY0aC0xeiIvPjxwYXRoIGQ9Ik0xMSAxM2EyIDIgMCAwIDAgMi0yVjguNzY0QTMgMyAwIDEgMSA4Ljc2NCAxM0gxMXoiIGZpbGw9IiMzRDQ3NTciLz48cGF0aCBmaWxsPSIjM0Q0NzU3IiBkPSJNMSAxM2gxMHYxSDF6Ii8+PHBhdGggZD0iTTEgMTNhMiAyIDAgMCAwIDItMlY4Ljc2NEEzIDMgMCAwIDEgMSAxNHYtMXoiIGZpbGw9IiMzRDQ3NTciLz48cGF0aCBmaWxsPSIjM0Q0NzU3IiBkPSJNMyA3aDF2NEgzeiIvPjwvZz48L3N2Zz4='; }
CommandBars(CommandBarId).Controls.Add(Type).TooltipText
Sets the tooltip text shown when a user hovers over a custom control using the TooltipText property.
-
Demonstration
Button

Drop-down list

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).TooltipTextexpression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button with an icon and tooltip. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; controlButton.Picture = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjM0Q0NzU3IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik04LjIxMyAxM0g2LjhsNi42MzYtNi42MzYtNC4yNDMtNC4yNDMtNy4wNyA3LjA3MUw1LjkyOCAxM0g0LjUxNUwxLjA2IDkuNTQ2YS41LjUgMCAwIDEgMC0uNzA3TDguODM5IDEuMDZhLjUuNSAwIDAgMSAuNzA3IDBsNC45NSA0Ljk1YS41LjUgMCAwIDEgMCAuNzA3TDguMjEzIDEzeiIgZmlsbC1ydWxlPSJub256ZXJvIi8+PHBhdGggZD0iTTQuNTM2IDYuMzY0bDQuOTUgNC45NS0uNzA3LjcwNy00Ljk1LTQuOTV6TTQuNTIxIDEzaDEwLjAzdjFINS40OTZ6Ii8+PC9nPjwvc3ZnPg=='; controlButton.TooltipText = 'Button tooltip'; // Add a custom drop-down list with an icon and tooltip. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; controlPopup.Picture = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik03LjUgMnYyLjVINGEuNS41IDAgMCAwLS41LjV2MmEuNS41IDAgMCAwIC41LjVoOWEuNS41IDAgMCAwIC41LS41VjVhLjUuNSAwIDAgMC0uNS0uNUg5LjVWMmEuNS41IDAgMCAwLS41LS41SDhhLjUuNSAwIDAgMC0uNS41eiIgc3Ryb2tlPSIjM0Q0NzU3Ii8+PHBhdGggZmlsbD0iIzNENDc1NyIgZD0iTTEzIDdoMXY0aC0xeiIvPjxwYXRoIGQ9Ik0xMSAxM2EyIDIgMCAwIDAgMi0yVjguNzY0QTMgMyAwIDEgMSA4Ljc2NCAxM0gxMXoiIGZpbGw9IiMzRDQ3NTciLz48cGF0aCBmaWxsPSIjM0Q0NzU3IiBkPSJNMSAxM2gxMHYxSDF6Ii8+PHBhdGggZD0iTTEgMTNhMiAyIDAgMCAwIDItMlY4Ljc2NEEzIDMgMCAwIDEgMSAxNHYtMXoiIGZpbGw9IiMzRDQ3NTciLz48cGF0aCBmaWxsPSIjM0Q0NzU3IiBkPSJNMyA3aDF2NEgzeiIvPjwvZz48L3N2Zz4='; controlPopup.TooltipText = 'Drop-down list tooltip'; }
CommandBars(CommandBarId).Controls.Add(Type).Visible
Shows or hides a custom control using the Visible property. Set Visible to false to hide the control without deleting it.
-
Demonstration
Show the item

Hide the item

-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).Visibleexpression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; // Add a custom drop-down list. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; // Hide both controls after 6,000 milliseconds. setTimeout(() => { controlButton.Visible = false; controlPopup.Visible = false; }, 6000); }
Commandbars(CommandBarId).Controls.Add(Type).With()
Sets multiple properties on a custom control in a single call using the With() method. For the full list of supported properties, see Individual custom elements or the properties overview table above.
-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).With(Properties)expression: a document type application object.
-
Parameters
Parameter
Data type
Required
Description
Caption
String
Yes
The label text displayed on the control.
Enabled
Boolean
No
Whether the control is interactive.
Picture
String
No
The icon of the control. Accepts a Base64-encoded image string.
Visible
Boolean
No
Whether the control is visible.
TooltipText
String
No
The tooltip text shown when hovering over the control.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and set multiple properties at once. const controlButton = await controls.Add(1); controlButton.With({ Caption: 'Button', Enabled: false, }); // Add a custom drop-down list and set multiple properties at once. const controlPopup = await controls.Add(10); controlPopup.With({ Caption: 'Drop-down list', Enabled: false, }); }
Event
CommandBars(CommandBarId).Controls.Add(Type).OnAction()
Listens for click events on a custom control using OnAction(). When the control is clicked, the assigned callback runs.
The Type parameter in Controls.Add(Type) determines the control type. Valid values:
|
Value |
Control type |
Description |
|
1 |
Button |
A clickable toolbar button. |
|
10 |
Drop-down list |
A drop-down control that opens a list when clicked. |
-
Syntax
expression.CommandBars(CommandBarId).Controls.Add(Type).OnAction() = Functionexpression: a document type application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Create a custom StartTab control. const controls = await app.CommandBars('StartTab').Controls; // Add a custom button and assign a click handler. const controlButton = await controls.Add(1); controlButton.Caption = 'Button'; controlButton.OnAction = () => console.log('Button clicked'); // Add a custom drop-down list and assign a click handler. const controlPopup = await controls.Add(10); controlPopup.Caption = 'Drop-down list'; controlPopup.OnAction = () => console.log('Drop-down list clicked'); }






