
📎 This article includes 1 downloadable practice file ↓
In this article
Office Scripts are Excel’s newer automation: scripts stored in OneDrive, written in TypeScript, running in Excel on the web and the new Excel desktop. Unlike VBA they can be triggered by Power Automate without anyone opening the file.
Find it
Excel on the web › Automate tab (needs a Microsoft 365 business or education licence). Record Actions captures what you do; New Script opens the code editor.
Record and read
Record: bold the header, fill it green, autofit columns. Stop. The editor shows code like:
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
sheet.getRange("A1:F1").getFormat().getFont().setBold(true);
}
Every script has a main function that receives the workbook. Objects (sheet, range, format) have get/set methods.
VBA vs Office Scripts
| VBA | Office Scripts | |
|---|---|---|
| Runs in | Desktop Excel | Excel web/new desktop, Power Automate |
| Language | VBA | TypeScript |
| Other apps (Outlook, files) | Yes | No (use Power Automate) |
| Stored | Inside the file | OneDrive, shareable |
Practice
Paste the script into a new Office Script, run it on a sheet with data, then record your own small macro and compare.
📎 Practice files for this article
- 📝Lesson 1 Office ScriptPaste into Excel on the web > Automate > New Script.⬇ TS · 429 B
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.
Stuck on a step? Ask a question and the AI answers using this article.