VBA & Macro Problems

Can Office Scripts Run When an Excel Sheet Is Activated?

Camila MilosovichCamila Milosovich Nov 11, 2026 869 views

Question details

The user needs to know if an Office Script can automatically execute when a specific Excel worksheet is activated.

Can Office Scripts Run When an Excel Sheet Is Activated?
Product
Microsoft Excel
Device & OS
not provided
Scenario
Trying to trigger an automation script based on an Excel worksheet activation event.
Observed behavior
Office Scripts currently do not support event-based triggers like worksheet activation; the documentation for such events refers to a different technology.
Before you start

Verify whether your automation relies on Office Scripts (TypeScript) or traditional VBA macros, as event handling capabilities differ significantly between the two technologies.

Solution 1Recommended

Use Office Add-ins or VBA for Event-Based Automation

Since Office Scripts do not support event triggers like onActivated, you must use the Office JavaScript automation model via an Office Add-in or rely on traditional VBA macros.

Office Scripts are designed for linear automation and currently do not support application or worksheet events. The 'onActivated' documentation you may have seen actually applies to the Office JavaScript API used for building Office Add-ins.

1
Identify your automation needs

Determine if your workflow strictly requires event-based triggers, such as a script running the moment a user clicks on a new sheet tab.

2
Explore Office Add-ins

Instead of Office Scripts, consider using the Office JavaScript API to build a custom add-in if you require modern web technologies.

3
Implement the onActivated event

Within your add-in code, register the Worksheet.onActivated event handler to run your specific functions automatically.

4
Use VBA as an alternative

If you are on desktop Excel, open the VBA Editor (Alt + F11), double-click a sheet in the Project Explorer, and use the native Worksheet_Activate event to trigger your macro.

Use Office Add-ins or VBA for Event-Based Automation
Important Distinction: Office Scripts and the Office JavaScript automation model are two different frameworks. Events are currently exclusive to Add-ins and VBA.
Free Microsoft Office alternative

Use WPS Office for Powerful Macro Support

If you need robust event handling like worksheet activation, WPS Office provides excellent support for VBA and JS macros as a free, lightweight Microsoft Office alternative.

  1. 1. Download WPS Office: Download and install the free WPS Office suite from the official website.
  2. 2. Open your macro-enabled workbook: Launch WPS Spreadsheet and open your existing .xlsm file containing your event-based macros.
  3. 3. Enable macros: Click 'Enable Macros' in the security warning prompt to allow your worksheet activation scripts to run seamlessly.
Native support for VBA macros including Worksheet_Activate eventsHighly compatible with Microsoft Office formats (.xlsx, .xlsm, .doc, .ppt)Lightweight and runs smoothly on older hardwareFree to use with a familiar tabbed interface
microsoft office alternative - wps office

Frequently Asked Questions

Can I use VBA instead of Office Scripts for sheet activation?

Yes, traditional VBA macros fully support event triggers. You can use the Worksheet_Activate event in the VBA editor to run code automatically when a specific sheet is selected.

Will Office Scripts support events in the future?

Currently, Microsoft has not implemented event-based triggers for Office Scripts. They are primarily designed for manual execution via the action pane or scheduled flows via Power Automate.

What is the difference between Office Scripts and Office Add-ins?

Office Scripts are simplified TypeScript codes meant for automating repetitive tasks by end-users, while Office Add-ins use the complete Office JavaScript API, allowing developers to create complex UI integrations and handle events like sheet activation.