If you spend a good part of your day repeating the same tasks in Excel Online, Office Scripts for Excel for the web can become your best friend. This feature lets you record what you do in a workbook, save it as a script, and run it again as many times as you want, without writing a single line of code if you don't want to complicate things.
In addition to simplifying processes, scripts allow your team to work more seamlessly: you share the workbook, you also share the scripts . This way, anyone with access to the file can launch your automations with the click of a button or integrate them into Power Automate workflows so everything happens in the background, even when no one has Excel open.
What are Office Scripts in Excel Web and what are they used for?
Office Scripts are a feature of Excel for the web that lets you automate repetitive steps within a workbook , such as formatting, cleaning data, creating tables, generating charts, or preparing reports. Everything runs in the cloud and is saved to your Microsoft 365 account, so you can reuse scripts across different workbooks and share them with your organization.
In practice, an Office script is a snippet of TypeScript code that Excel executes on a specific workbook. This code can be generated by recording your actions with the Recorder , edited later in the Code Editor, or even created from scratch if you have basic programming knowledge.
Imagine opening a CSV file downloaded from your accounting software every morning. You always follow the same steps: remove unnecessary columns , apply table formatting, add formulas, and create a pivot table. With Office Scripts, you perform this process only once using the Recorder, and from then on, simply clicking a button allows Excel Web to repeat the entire data transformation workflow for you.
The great advantage is that you not only save time, but you also reduce human error. A well-prepared script always runs the same way, without missing steps or making mistakes in cells or ranges . And if you share the file with your team, anyone can run the exact same process without knowing all the technical details.
In professional settings, these scripts are being used for tasks as varied as standardizing sales listings, generating daily reports, updating dashboards, and preparing invoice templates. The more repetitive and structured the task , the more sense it makes to invest a few minutes in converting it into a script.

When does it make sense to use Office Scripts
Office Scripts are especially useful when you find yourself performing the same actions on different workbooks or versions of the same file. If you repeat a series of steps in Excel Web every day, week, or month, the ideal solution is to convert that sequence into a reusable script that you can run on one or more workbooks without having to redo everything manually.
A typical example is users working with imported data : CSV files from banks, ERP exports, marketing tool reports, etc. In all these scenarios, the workflow is usually very similar: clean, transform, format, and summarize information . Documenting the process once and converting it into a script prevents each team member from doing it their own way.
It also makes a lot of sense in collaborative processes. If several colleagues need to prepare the same type of report, you can create a single script that standardizes the procedure. This way, the results are consistent, replicable, and easy to maintain , because any subsequent changes are made to the script and propagated to everyone who uses it.
Automation can be taken a step further by combining scripts with Power Automate. This allows you to not only launch them manually from Excel, but also schedule their execution to occur periodically or trigger them when an external event happens, such as an incoming email or a file update in OneDrive or SharePoint.
If you already use advanced formulas, pivot tables, or data models in your daily work, you likely have significant room for improvement. Switching from manual clicks to automated scripts can save you hours each week and free up time for valuable analysis instead of repetitive tasks.
Action recorder: automate without knowing code
The Action Recorder is the easiest entry point to Office Scripts. This tool records every step you take in the workbook (editing cells, changing formats, inserting tables, etc.) and automatically translates it into an executable script.
It works very simply: you start recording, complete the tasks in Excel as you normally would, and when you stop, you get a script that you can save, rename, and run again whenever you want. The idea is similar to classic Excel macros , but focused on the Excel for the web environment and based on TypeScript.
When you play that script in other workbooks or worksheets, Excel tries to replicate exactly what you recorded: it applies the same operations to the ranges and objects used during the recording. This makes it an ideal solution for users without programming knowledge who want to automate well-defined processes.
However, it's important to note that not all actions are yet available in the Recorder. Some Excel features are not recorded, and in that case, a note will appear indicating that the action will not be added to the script . These parts are simply omitted, so it's advisable to review the output and, if necessary, complete it using the Code Editor.
Microsoft's help articles on "Recording actions as an Office script" delve deeper into this approach, explaining what operations are captured, how the scripts are stored, and how to manage them from the Automate tab in Excel Web.

Code editor: customize and create advanced scripts
The Code Editor is the environment where you can view, modify, and write Office scripts . It allows you to open a script recorded with the Recorder, read the generated TypeScript code, and adjust it to your needs, adding more complex logic or improving its robustness.
This editor allows you to introduce programming constructs that the Excel interface doesn't directly offer: conditionals (if/else), loops, helper functions , error handling, and more. This enables the script to not only perform fixed actions but also make decisions based on the data or the workbook's structure.
Microsoft provides guided tutorials that show you step-by-step how to go from a simple recording to a more elaborate script. These resources explain how to interpret the code generated by the Recorder , how to organize it into functions, and how to get the most out of the Code Editor environment.
If you'd like to go a step further, there's also the option of writing a script with the help of AI . This feature, still in its preliminary stages, generates a script draft that you can review, understand, and adapt. It's a convenient way to get a starting point, especially if you already know what you want to achieve but haven't yet mastered all the TypeScript syntax.
The materials in “Basics for Office Scripts in Excel” and the Code Editor environment documentation are an important support for understanding how to organize your scripts, how to debug them, and how to take advantage of the available APIs.
TypeScript and the internal structure of an Office script
Office Scripts are written in TypeScript, a typed superset of JavaScript . If you already have some experience with JavaScript, the transition is relatively smooth: the basic syntax is virtually the same, and the types add security and clarity to your code.
Every script must contain a function main which acts as an entry point. This function always receives an object of type as its first parameter. ExcelScript.Workbook, which represents the Excel workbook you will be working on. The typical minimum signature would look something like this: function main(workbook: ExcelScript.Workbook) { /* código */ }.
The code you place inside main This is what will be executed when you run the script from Excel or Power Automate. You can define helper functions within the same file and call them from there. mainbut any instruction that falls outside a function will not be executedFurthermore, Office scripts cannot directly invoke other scripts; that orchestration is achieved through Power Automate.
Regarding the available APIs, there are two main namespaces: ExcelScript for everything related to the book (sheets, ranges, tables, charts…) and OfficeScript for more general functions not tied to a specific document. The reference documentation lists all the classes, methods, and properties available within these namespaces.
A typical flow within a script would consist of using the object workbook to obtain the active sheet, locate specific ranges, read or write values and, if necessary, create or modify tables, charts, pivot tables, or other objectsEach of these elements has its own API, but they all relate coherently to what you see in the Excel interface.

The Excel object model in Office Scripts
To work comfortably with Office Scripts, it's important to understand how objects are structured within the workbook. Broadly speaking, Excel is organized around a hierarchical object model that mirrors the user interface itself.
The object is at the top Workbookwhich represents the complete book. This contains one or more spreadsheets (WorksheetEach sheet, in turn, provides access to cell ranges (Range), which can be used to create tables, charts, shapes, and other visual or organizational elements.
A spreadsheet manages collections of objects (tables, charts, images, etc.) that exist within it. Similarly, a workbook also has global collections for certain objects, such as all the tables in the workbook , even if they are spread across multiple sheets. This approach makes it easy to access entire sets of elements, filter them, or loop through them.
The official Office Scripts API documentation includes complete listings of all objects, methods, and properties, organized into packages. ExcelScript y OfficeScriptConsulting them is very useful when you want to go beyond what the Recorder offers and you need fully understand what you can do from code.
Once you internalize this model, it becomes easier to read and write scripts, because you'll see that the code almost directly reflects the structure of the book: you start "at the top" in the Workbook, go down to the sheets, and from there to the specific ranges and objects you need to manipulate.
Ranges: values, formulas, and formatting
The object Range It is one of the pillars of Office Scripts. A range is, basically, a set of contiguous cells, usually identified by A1 notation (for example, "B3" for a cell or "C2:F4" for a block of several rows and columns).
Each range has three main groups of properties: values, formulas and format. Through methods such as getValues, getFormulas y getFormat You can read the contents of the range; with setValues y setFormulas You can write new values or formulas, while the formatting is managed by an object. RangeFormat, which in turn It includes properties for background color, font, borders, and alignment., etc.
Information within a range is handled as two-dimensional arrays (arrays of arrays), where each subarray represents a row. This means that, when working with tabular data, you can construct structures like , ] and assign them all at once to a block of cells.
It's also important to understand the types of values that a range returns. Each cell can contain a string, a number or a booleanIf you want to perform arithmetic operations on values obtained from cells, it is advisable to explicitly declare the type, for example, using as number[][] after calling getValuesso that TypeScript knows you're dealing with numbers and not text.
A practical example would be calculating the average price of a column in a table: you get the price range, declare it as an array of numbers, and iterate through its elements with a loop or a forEach y Apply whatever logic you needThis pattern is repeated in many scripts: identify the appropriate range, read the values, process them in TypeScript and, if necessary, write the results to other cells.
Tables, charts, and other data objects
In addition to manipulating individual cells or flat ranges, Office Scripts allows you to work with richer data structures such as tables, charts, pivot tables, shapes, and images . All of this is controlled through its specific APIs, but always starting from cell ranges.
Creating a table is as simple as taking a range that already contains data and calling addTable on the corresponding sheet. You can specify whether the first row of the range contains headers, and Excel will automatically apply them accordingly. filters, table format and styleThen, that table will have its own methods for managing columns, rows, filters, totals, styles, etc.
The charts are constructed in a similar way: you select a range of data and call addChart specifying the chart type (for example, stacked columns). Once created, you can change its position, size, and many other properties, from the title to the colors or the series type. Scripts can generate full visualizations starting from raw data with very few lines of code.
For pivot tables, shapes, or other objects, the approach is similar: they are created from ranges or retrieved from collections in the sheet or workbook, and then manipulated as needed. The specific documentation for each object type explains which operations are supported and how to combine multiple pieces to create complex reports.
This high-level object manipulation is especially useful when you want a script to leave the workbook "ready to use": it not only fills in data, but also builds complete structures and visualizations so that the user only has to open the sheet and analyze the result.

Collections and working with various objects
Many Excel objects group others into collections. The clearest example is the workbook, which has a collection of worksheets , but this also occurs with tables (collection of columns), worksheets (collection of charts), and so on.
In Office Scripts, these collections are typically exposed as standard TypeScript arraysMethods such as workbook.getWorksheets() o worksheet.getCharts() They return an array with all the elements of that type. Thanks to that, you can iterate through them with forEachfilter with filter or access a specific element by index.
In addition, there are usually methods get singular that accept an identifier or name and return a single object or undefined if it doesn't exist. For example, workbook.getTable("MyTable") Try to locate a table with that name. This pattern is very useful when you need to check if an item has already been created. before manipulating or regenerating it.
A very common pattern in scripts is: search for a table by name, if it exists you delete it with delete() Then you create a new table with updated data and the same name. This way, You avoid conflicts with duplicate names or remnants of old information that may confuse users.
The documentation on “Working with Collections” explains these patterns in more detail and shows examples of how to iterate through all the tables in a workbook to apply a common style, ensure that headers are visible, or activate filter buttons in bulk.
Add and delete Excel objects from a script
With Office Scripts, you can not only modify what already exists, but you can also programmatically create and delete objects in the workbook . This includes tables, charts, worksheets, and other data-related elements.
To add an object, the normal thing to do is to call a method add on the appropriate parent object. For example, to create a table on the first sheet of the workbook, you get that sheet with workbook.getWorksheets() and you call addTable specifying the range and whether it has headers. The method returns the table itself, allowing you to configure it afterward (name, style, totals, etc.).
This dynamic creation capability facilitates scenarios where, each time the script runs, a complete report is rebuilt from scratch . Furthermore, if you combine this with a pre-existence check, you can first delete any previous versions and ensure that the workbook is always in a clean and consistent state.
To delete objects, the general rule is to call their method delete()You can do this with tables, charts, or even entire spreadsheets. For example, to get the first sheet of a workbook with getWorksheets() and then call delete() Remove that page from the book.
Properly managing the creation and deletion of objects is crucial when scripts run periodically or when multiple users work on the same file . This prevents the accumulation of outdated sheets, duplicate tables, or charts that no longer reflect current data.
Share and run Office Scripts as a team
Once you have a useful script, you'll naturally want others to be able to benefit from it as well. Office Scripts allows you to share scripts within your organization through shared Excel for the web workbooks.
When you publish a book and grant access to your team, other users with permissions can view and run the scripts associated with that file. This allows a single specialist to create the automation , and the rest of the team can simply use it from the Automate tab without having to delve into technical details.
To make it even easier to use, you can add script buttons directly to the ribbon or the script gallery. This way, a user only needs to click a clearly labeled button to launch the process that cleans data, updates reports, or generates tables , without having to navigate through complicated menus.
Managing which scripts are shared, who can view or modify them, and how they are integrated into each workbook is explained in detail in the documentation on "Sharing Office Scripts in Excel." It is advisable to review these options, especially in large organizations where governance and process standardization are crucial.
Furthermore, sharing not only saves time but also encourages reuse and continuous improvement. A colleague might identify a specific issue, suggest a change to the script, and after the team refines it, the entire organization benefits from the new version.
Program scripts and connect them to Power Automate
One of the most powerful features of Office Scripts emerges when you combine them with Power Automate. This integration allows you to schedule scripts to run in the background or have them respond automatically to external events.
From the Code Editor, you'll find a "Scripting" section. There, you can log in to Excel through Power Automate, define how often you want the script to run (daily, weekly, every few hours, etc.), and finally, click "Create flow" to let Power Automate take care of the rest.
Once configured, the Power Automate workflow runs even if the workbook is closed or no one has the browser open. This is especially useful for keeping reports or dashboards up to date , or for performing data maintenance tasks outside of business hours.
In addition to scheduling, Power Automate allows you to trigger scripts in response to specific actions: receiving emails, changes to OneDrive or SharePoint files, form submissions, and so on. This lets you design workflows where, for example, every time a CSV file is uploaded to a folder , an Excel script runs to clean, format, and update the corresponding tables and charts.
The tutorial “Running Office Scripts with Power Automate” explains step by step how to set up these connections, how to pass parameters to the script, and how to collect values returned from the function. main and use this information in the rest of the automation flow.
Requirements, common problems and troubleshooting
To use Office Scripts in Excel for the web , your Microsoft 365 license must include this feature . Additionally, in enterprise environments, the administrator can enable or disable scripting from the Microsoft 365 admin center or through Group Policy.
If you don't see the "Automate" tab in Excel Web, there are several recommended checks: ensure your account isn't a guest account in the tenant, check that the administrator hasn't blocked the functionality, and verify that third-party cookies are enabled in your browser . On Windows, WebView2 may also need to be installed for certain features to display correctly.
Regarding runtime errors, a common problem is that the workbook where the script is being run doesn't have the exact same structure as the workbook where it was saved. For example, a table with a specific name might be missing, or a sheet might have a different name. In these cases, the Code Editor will display error messages and indicate where execution has stopped.
From the Editor panel, you can click "View Logs" to see a brief summary of the error. This will help you locate the problematic line and adjust the script to make it more robust, using pre-checks or adapting the sheet and object names.
Finally, keep in mind that not all Excel features are yet compatible with the Recorder or the Office Scripts APIs . When you try to record an unsupported action, a note will appear in the Recording pane indicating that it will be skipped. In such cases, you may need to find a code-based alternative or accept that this specific part will not be automated for the time being.
Learn and train in Office Scripts in Excel web
To get the most out of this functionality, a solid understanding of Excel and its web version is highly recommended . If you're already comfortable with formulas, tables, filters, and some pivot tables, you're ideally positioned to take the leap into automation with scripts.
There are specific courses focused on Office Scripts in Excel for the web that rely on very practical examples. These courses cover everything from recording and basic script editing to the differences with VBA and ways to combine both approaches when also working with desktop Excel.
These courses typically teach how to add custom buttons to launch scripts intuitively, how to share workbooks so the rest of the team can use your automations, and how to run scripts in collaborative contexts, for example, within Microsoft Teams , further expanding automation possibilities.
No prior programming experience is necessary: the tutor typically guides you step-by-step through reading and understanding the generated code, analyzing examples such as creating automated invoice templates or data cleaning routines. The goal is for you to be able to apply what you've learned from day one and see a real impact on your daily tasks.
In addition to formal training, Microsoft's own technical documentation, interactive tutorials, and sample scripts are key resources for continued learning. There you'll find everything from beginner's guides to detailed references on the object model and advanced examples for real-world business scenarios.
By combining functional Excel knowledge with these learning resources and a little practice, it becomes relatively quick to move from completely manual tasks to highly automated processes with Office Scripts in Excel Web.