Office Scripts in Excel for the Web: Your First Script, Explained Like VBA

⏱ 3 min readUpdated 28 September 2026

If your company moved to Microsoft 365 and your files now live in SharePoint or OneDrive, you have probably noticed that VBA macros do not run in Excel in the browser. Office Scripts are Microsoft’s answer: macros that run in Excel for the web, written in TypeScript, and able to run on a schedule without anyone opening the file.

In this article
  1. Where to find it
  2. VBA vs Office Scripts in one table
  3. Record first, then read
  4. A real example: clean a daily export
  5. Running it without opening the file
  6. Where it falls short

Where to find it

Open a workbook in Excel for the web and look for the Automate tab. If it is missing, your admin may have switched Office Scripts off, or your licence may not include it (business and enterprise plans usually do; personal plans often do not).

VBA vs Office Scripts in one table

VBA Office Scripts
Runs in Desktop Excel Excel for the web (and newer desktop builds)
Language VBA TypeScript
Stored Inside the workbook In your OneDrive, separate from the file
Can touch other files, Outlook, the PC Yes No — only the workbook it runs on
Scheduled / triggered runs Needs Task Scheduler and a PC left on Power Automate, in the cloud

The restriction on touching other things is deliberate. A script cannot delete files on your laptop or send emails by itself, which is why IT departments are more relaxed about it.

Record first, then read

Click Automate › Record Actions, do something simple — bold the header row, set a column width, sort by date — and stop. Then open the code. You will see something like:

function main(workbook: ExcelScript.Workbook) {
  let sheet = workbook.getActiveWorksheet();
  sheet.getRange("A1:F1").getFormat().getFont().setBold(true);
  sheet.getRange("A:A").getFormat().setColumnWidth(90);
}

Every script has a main function that receives the workbook. From there it is objects and methods, the same idea as VBA’s Worksheets("Sheet1").Range("A1") but with get… and set… calls.

A real example: clean a daily export

A typical job: a system dumps a sheet every morning with blank rows, amounts stored as text and a useless column C. This script fixes all three and adds a table.

function main(workbook: ExcelScript.Workbook) {
  const ws = workbook.getWorksheet("Export");
  ws.getRange("C:C").delete(ExcelScript.DeleteShiftDirection.left);

  const used = ws.getUsedRange();
  const values = used.getValues();
  // walk from the bottom so deleting a row does not skip the next one
  for (let r = values.length - 1; r > 0; r--) {
    if (values[r].every(v => v === "")) {
      used.getRow(r).delete(ExcelScript.DeleteShiftDirection.up);
    }
  }

  const amount = ws.getUsedRange().getColumn(4);
  amount.setNumberFormatLocal("#,##0.00");
  amount.setValues(amount.getValues().map(row => [Number(row[0]) || row[0]]));

  ws.addTable(ws.getUsedRange(), true).setName("DailyExport");
}
💡 Reading all values at once with getValues(), changing them in memory and writing once with setValues() is much faster than touching cells one by one. It is the same advice as for VBA arrays.

Running it without opening the file

In Power Automate create a Scheduled cloud flow, add the action Excel Online (Business) › Run script, choose the file and script, and set it for 8:00 every weekday. Your file is cleaned before you arrive, even if your laptop is off.

Where it falls short

  • No access to other workbooks directly — you pass data between them through Power Automate.
  • No UserForms. Inputs come from cells or from flow parameters.
  • Long scripts can time out in flows. Keep each script focused.

If your team is still on desktop files, VBA remains the more capable choice — start with the VBA course. If everything is in the cloud, Office Scripts plus Power Automate is where Microsoft is heading.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong