How to Run the Same Office Script with Different Excel Filters
Question details
The user wants to reuse an Office Script's logic to apply different filter criteria in Excel, given that one Office Script cannot directly invoke another.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating data filtering across different conditions in an Excel workbook using Office Scripts.
- Observed behavior
- Office Scripts do not feature a built-in method to call one script from another, requiring a workaround to programmatically apply multiple filter criteria.
Ensure you have an active Microsoft 365 subscription with Office Scripts enabled for your account, and basic familiarity with the Code Editor in Excel on the web or desktop.
Consolidate Logic Using the ExcelScript.Filter Interface
Since Office Scripts cannot call one another, the most effective solution is to write a single, reusable script that uses the ExcelScript.Filter interface to apply different filter criteria programmatically.
Instead of trying to chain multiple scripts, you can utilize the powerful filtering methods available within the ExcelScript API. By passing different values to methods like applyValuesFilter or applyCustomFilter within one master script, you can achieve dynamic filtering.
Navigate to the Automate tab on the Excel ribbon and click on Code Editor to create a new script or edit an existing one.
In your main function, declare the range or table where the filter will be applied. For example: let table = workbook.getTable('MyTable'); or let range = workbook.getActiveWorksheet().getUsedRange();
Get the AutoFilter object for the specific column you want to filter. For instance: let columnFilter = table.getColumnByName('Category').getFilter();
Use columnFilter.applyValuesFilter(['Value1', 'Value2']) to filter by specific text, or use applyCustomFilter() for more complex criteria like dates or numbers.

Try WPS Office for Advanced Spreadsheet Automation
If you are looking for an alternative to Microsoft 365's Office Scripts, consider WPS Office. It provides robust built-in support for both traditional VBA and modern JavaScript (JS) Macros, allowing you to easily automate data filtering tasks without expensive subscriptions.
- 1. Download and Install WPS Office: Visit the official WPS website to download the free suite and install it on your device.
- 2. Open Your Excel File: Launch WPS Spreadsheet and seamlessly open your existing .xlsx or .xlsm files.
- 3. Automate with JS Macros or VBA: Go to the Tools tab on the ribbon to access the Macro Editor, where you can write powerful scripts to filter and manage your data.

Frequently Asked Questions
Can one Office Script trigger another Office Script?
No, Office Scripts currently do not support calling or triggering one script directly from another. You must combine the required logic into a single script or orchestrate multiple scripts using a Power Automate flow.
What is the ExcelScript.Filter interface?
The ExcelScript.Filter interface is part of the Office Scripts API that allows you to manage the AutoFilter of a worksheet or table. It includes methods to apply, clear, and configure filters programmatically.
How do I clear existing filters before applying new ones in an Office Script?
You can clear existing filters by calling the clearFilter() method on the worksheet's or table's AutoFilter object before applying your new criteria using the apply methods.
Can I pass external variables into an Office Script to alter the filter?
Yes. By adding parameters to the main function (e.g., function main(workbook: ExcelScript.Workbook, myFilterCriteria: string)), you can pass external values into the script when calling it via Power Automate, making your script highly reusable.




