Office Scripts: Automate Excel on the Web Without VBA

Office Scripts: Automate Excel on the Web Without VBA

📎 This article includes 2 downloadable practice files ↓

⏱ 2 min readUpdated 27 September 2026

VBA does not run in Excel for the web. Microsoft’s answer is Office Scripts: automation written in TypeScript (JavaScript with types), stored in OneDrive, and runnable from the browser or from Power Automate. You find it under the Automate tab (it needs a Microsoft 365 business or school account).

In this article
  1. Record first, then read
  2. A useful script: format any report
  3. VBA vs Office Scripts
  4. Try it yourself: step by step

Record first, then read

  1. Automate → Record Actions, do a few steps (type a header, make it bold, fill yellow), then stop.
  2. Click Edit to see the code. Every script has the same shape:
function main(workbook: ExcelScript.Workbook) {
  let sheet = workbook.getActiveWorksheet();
  sheet.getRange("A1").setValue("Sales Report");
  sheet.getRange("A1").getFormat().getFont().setBold(true);
}

A useful script: format any report

function main(workbook: ExcelScript.Workbook) {
  const sheet = workbook.getActiveWorksheet();
  const used = sheet.getUsedRange();
  if (!used) return;

  // header row
  const header = used.getRow(0);
  header.getFormat().getFont().setBold(true);
  header.getFormat().getFill().setColor("#217346");
  header.getFormat().getFont().setColor("white");

  // number format for every column after the first
  const body = used.getOffsetRange(1, 1).getResizedRange(-1, -1);
  body.setNumberFormatLocal("#,##0");

  sheet.getFreezePanes().freezeRows(1);
  used.getFormat().autofitColumns();
}

VBA vs Office Scripts

VBA Office Scripts
Runs in Desktop Excel (Windows/Mac) Excel for the web, and desktop Excel for Microsoft 365
Language VBA TypeScript
Other apps Can control Outlook, Word, the file system Workbook only; use Power Automate to reach other services
Scheduling Needs a PC left running Power Automate cloud flows on a schedule
💡 The killer feature is the Power Automate connector “Run script”: every morning a flow can open a workbook in SharePoint, run your script and email the result — no PC needed.

New to the syntax? Read JavaScript for Excel users first.

Try it yourself: step by step

  1. Upload report-to-format.xlsx to OneDrive and open it in Excel for the web.
  2. Automate → New Script, delete the sample code and paste format-report.ts.
  3. Click Run: the header turns green, numbers get separators, the top row freezes and columns resize.
  4. Save the script with a name like “Format report”. It now appears in the Automate gallery for any workbook.
  5. Optional: in Power Automate create a scheduled cloud flow with the Excel Online action Run script to format the file every morning.

📎 Practice files for this article

  • 📝
    Office Script (.ts)Paste into Automate u2192 New Script in Excel for the web.
    ⬇ TS · 588 B
  • 📗
    Unformatted reportUpload to OneDrive, open in Excel for the web and run the script.
    ⬇ XLSX · 8 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.