📊 Lesson 6.3: A Taste of Macros/VBA & Office Scripts (Honest Scope)
Last lesson, Power Query showed you that repetitive data cleanup can be recorded once and refreshed forever. This lesson takes that idea to the whole workbook: automation. If you find yourself doing the same clicks every day — formatting a report, adding totals, cleaning a layout — Excel can record those actions and play them back. We'll take an honest taste of two ways to do it: classic Macros/VBA and modern cloud-based Office Scripts — and we'll be candid about what runs where.
📚 What You'll Learn
By the end of this lesson, you will be able to:
- Explain what automation is and honestly judge when it's worth it (and when it isn't)
- Describe the macro recorder and where VBA lives — the Developer tab and
.xlsmfiles — plus its honest limits and security concerns - Read a tiny recorded-macro example and understand what it does
- Describe Office Scripts — the modern, cloud/web TypeScript automation — and why it's more portable
- Place Power Automate and Google Sheets' Apps Script in the picture, and keep realistic expectations of this taste
⏱️ Estimated Time: 45 minutes
🎯 Project: Record a simple macro (desktop) or Office Script (web) that formats or repeats a task, run it, and inspect what it recorded.
In This Lesson
What Automation Is — and When It's Worth It
Automation means recording a sequence of actions once and having Excel replay them on command, so you don't repeat the same clicks by hand. Every day someone opens a fresh report, autofits the columns, bolds the header row, adds a total, and formats it as currency — the same eight steps, over and over. Automation turns those eight steps into a single button.
But — and this is the honest part — automation is not always the right answer. It carries a setup cost and a maintenance cost, and if you spend an hour automating a task you do once a year, you've lost money on the deal. The useful rule of thumb: automate when a task is repetitive (you do it often), predictable (the same steps every time), and tedious or error-prone by hand. A one-off, judgment-heavy, or constantly-changing task is usually better done manually.
often?"} B -->|No, it's a one-off| C["Just do it by hand"] B -->|Yes| D{"Same predictable
steps each time?"} D -->|No, needs judgment| C D -->|Yes| E{"Tedious or
error-prone?"} E -->|Not really| C E -->|Yes| F["Good candidate
to automate"]
💡 The "rule of three" instinct
A friendly gut-check: the third time you catch yourself doing the exact same manual routine, pause and ask "should I record this?" Once is a fluke, twice is a coincidence, three times is a pattern — and patterns are what automation is for. Don't automate speculatively; automate the drudgery you can already feel.
Macros & VBA — the Classic Way
The original, deep automation in Excel is the macro, powered by a language called VBA (Visual Basic for Applications). It's been in Excel for decades, and enormous amounts of business automation still run on it. The friendly on-ramp is the macro recorder: you press record, do your task by hand, press stop — and Excel writes the VBA code for you, capturing every action. No coding required to create one.
Where it lives
- The Developer tab. Macro tools live on the Developer ribbon tab, which is hidden by default — you turn it on in File > Options > Customize Ribbon (on Mac, via Preferences). It holds Record Macro, Macros (to run them), and the Visual Basic editor where the code lives.
- The
.xlsmfile. A normal.xlsxworkbook cannot store macros. To keep macros, you must save as a macro-enabled workbook — the.xlsmformat. This is a deliberate safety design, and it's why you'll be prompted to change format when you save a workbook that contains a macro.
A tiny recorded macro, read out loud
Suppose you turn on the recorder and do three things to a header row: make it bold, give it a light fill, and autofit the columns. Excel records VBA that looks roughly like this:
Sub FormatHeaderRow()
' Recorded macro: format the header row
Range("A1:D1").Select
Selection.Font.Bold = True
Selection.Interior.Color = RGB(226, 240, 233)
Columns("A:D").EntireColumn.AutoFit
End Sub
You don't need to write that — the recorder did — but you can read it, and that's the point of the
taste. Sub FormatHeaderRow() names the macro; the line starting with an apostrophe is a comment;
Range("A1:D1").Select selects the header; the next lines set bold, a fill color, and autofit; and
End Sub closes it. Run it later from Developer > Macros (or a keyboard shortcut
you assign) and those formatting steps happen instantly. Once you can read recorded code, you can tweak it — the
doorway from "recording" to "light programming."
⚠️ Honest limit: VBA is Windows-desktop-first
Be clear-eyed here. The macro recorder and the full VBA editor are a desktop feature — richest on
Windows. The Mac desktop app supports VBA but with some differences and gaps.
Excel for the web does not run VBA macros at all — open an .xlsm in the browser
and the macros simply won't run (the data is still safe to view). So VBA is powerful and deep, but it is
not portable to the web, which is exactly why Microsoft built the modern alternative we'll meet next.
Macro Security — Read This
Because a macro can do things — change files, and in principle reach outside the workbook — macros are
also a classic malware vector. For years, malicious .xlsm files were a favorite way to trick people
into running harmful code. So Excel guards them carefully, and you must understand these guardrails.
- Macro-enabled files are marked. The
.xlsmextension itself is a flag: this file can contain code. A plain.xlsxis guaranteed macro-free. - The enable-content prompt. Open a workbook with macros and Excel shows a security warning — often a yellow bar — asking whether to Enable Content. Macros stay disabled until you say yes.
- Files from the internet are extra-restricted. Workbooks downloaded from the web or email may open in a protected state with macros blocked more firmly, precisely because that's where danger comes from.
🔒 The one security rule that matters most
Never enable macros in a workbook you don't fully trust. If a file arrives unexpectedly by email, or from someone you don't know, and it demands you "Enable Content" to work — treat that as a red flag, not an instruction. Enable macros only in files you created or that come from a genuinely trusted, verified source. When in doubt, don't. This single habit prevents the large majority of macro-based trouble.
⚠️ Important Note: None of this should scare you off writing your own macros in your own workbooks — that's completely safe and genuinely useful. The caution is entirely about running other people's macro-enabled files without thinking. Create freely; enable cautiously.
Office Scripts — the Modern, Cloud Way
Meet the modern answer to VBA's biggest limitation. Office Scripts is Excel's newer automation system, built for the cloud. You'll find it on the Automate tab in Excel for the web (and it also runs from the current Windows desktop app when signed in with a suitable Microsoft 365 account). Like VBA it has a recorder — Record Actions — but the code it writes is TypeScript (a modern, JavaScript-based language) instead of VBA.
The same header-formatting task recorded as an Office Script reads something like this:
function main(workbook: ExcelScript.Workbook) {
// Recorded Office Script: format the header row
let sheet = workbook.getActiveWorksheet();
let header = sheet.getRange("A1:D1");
header.getFormat().getFont().setBold(true);
header.getFormat().getFill().setColor("E2F0E9");
sheet.getRange("A1:D1").getFormat().autofitColumns();
}
Notice it does the same job as the VBA macro — bold, fill, autofit — but in a different language and, crucially,
a different place. Office Scripts are stored in your OneDrive/Microsoft 365 cloud, not baked into an
.xlsm file, so you run them from the Automate tab on any machine, and you can even trigger them as
part of larger automated flows. That portability is the whole point.
| Aspect | Macros / VBA | Office Scripts |
|---|---|---|
| Language | VBA (Visual Basic for Applications) | TypeScript (JavaScript-based) |
| Runs on | Desktop — richest on Windows; not on the web | Excel for the web and current Microsoft 365 desktop |
| Where it's stored | Inside the .xlsm file |
In your OneDrive / Microsoft 365 cloud |
| Recorder | Record Macro (Developer tab) | Record Actions (Automate tab) |
| Best for | Deep, legacy, desktop-only automation | Modern, portable, cloud & shareable automation |
⚠️ Honest scope: Office Scripts needs the right account
Office Scripts is a Microsoft 365 feature and availability depends on your plan and your organization's settings — it appears via the Automate tab and may not be present on every free personal account or in every tenant. If you don't see an Automate tab, that's a plan/availability matter, not a mistake on your part. As always, check Microsoft's current pages for what your account includes.
Power Automate & the Bigger Picture
One step beyond scripting a single workbook is automating a whole process across apps. Power Automate is Microsoft's separate service for building automated flows — "when X happens, do Y" chains that connect Excel to email, Teams, forms, approvals, and hundreds of other services. For example: when a new response lands in a form, add a row to an Excel table and post a message in Teams. Office Scripts can be called as a step inside a Power Automate flow, which is where the modern, cloud-first automation story really comes together. We mention it here only so the name is on your radar — building flows is well beyond a taste, but knowing the tool exists tells you where to look when a task spans more than just Excel.
💡 Compared to Google Sheets — Apps Script
Google Sheets' automation counterpart is Apps Script — a cloud, JavaScript-based system with its own macro recorder, conceptually very close to Office Scripts. If you've written Apps Script, Office Scripts will feel familiar (both are JavaScript-family, both cloud, both recorder-plus-code). The honest landscape: Excel gives you a choice — deep desktop VBA and modern cloud Office Scripts — while Sheets centers on the single cloud-native Apps Script. Different histories, same underlying goal: replace repetitive clicks with code.
Honest Scope & Best Practices
⚠️ This is a taste, not a programming course
Let's set expectations honestly. This lesson is a guided taste of automation, not a coding course. The goal is that you can record a simple macro or script, run it, read what it captured, and judge when automation is worth it — not that you'll write programs from scratch. Real VBA and TypeScript development are large skills in their own right. If this sparks something, that's wonderful — the recorder is the perfect first rung of that ladder — but you can be a highly effective Excel user with only this much automation and never write a line by hand.
✅ Do's
- Automate the repetitive, predictable, tedious. Save the effort for tasks you truly repeat.
- Record first, then read. Let the recorder write the code, then look at it to learn and lightly tweak.
- Match the tool to the platform. VBA for deep desktop work; Office Scripts when you need web and portability.
- Save macro workbooks as
.xlsmso your macros are actually kept.
❌ Don'ts
- Don't enable macros in files you don't trust. The single most important security habit — treat an unexpected "Enable Content" as a red flag.
- Don't automate one-offs. If you'll do it once, just do it — the setup cost isn't worth it.
- Don't expect VBA to run on the web. It won't; reach for Office Scripts there.
- Don't feel you must learn to code. The recorder alone covers a great deal; go deeper only if you want to.
💡 Pro Tips
- Give macros and scripts clear names (
FormatHeaderRow, notMacro1) so future-you knows what each does. - Before recording, rehearse the exact steps once by hand — the recorder captures everything, including mistakes.
- Keep a plain
.xlsxcopy of important data; do your macro experiments in the.xlsm.
🎯 Project: Record Your First Automation
Time to feel the magic yourself. You'll record a tiny automation that formats a header row, run it on fresh data, and then inspect the code it wrote. Use whichever path matches your setup — the experience and the lesson are the same either way.
🏋️ Record, run, and read a simple automation
Objective: Create a recorded macro (desktop) or Office Script (web) that formats a header row, run it, and read what it captured.
Instructions (about 15 minutes):
- (2 min) Set up. Put a small header row and a few data rows on a sheet (e.g.
Date | Category | Amountin A1:C1 with a couple of rows below). - (2 min) Start recording. Desktop: turn on the Developer tab
(File > Options > Customize Ribbon), then Developer > Record Macro, name it
FormatHeaderRow. Web: Automate > Record Actions. - (3 min) Do the task by hand: select the header row, make it bold, apply a fill color, and autofit the columns.
- (1 min) Stop recording (Stop Recording on desktop, or Save the script on the web).
- (3 min) Test it: clear the formatting (or add a new similar table) and run your macro/script — watch the formatting apply instantly.
- (3 min) Inspect it: open Developer > Visual Basic (desktop) or the script editor (web) and read the recorded code. Find the line that sets bold and the line that autofits — you'll recognize them from this lesson.
- (1 min) If on desktop, save the workbook as
.xlsmso the macro is kept.
💡 Hint — what your recorded code should resemble
' VBA (desktop) — Developer > Visual Basic
Sub FormatHeaderRow()
Range("A1:C1").Select
Selection.Font.Bold = True
Selection.Interior.Color = RGB(226, 240, 233)
Columns("A:C").EntireColumn.AutoFit
End Sub
// Office Script (web) — Automate tab
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getActiveWorksheet();
let header = sheet.getRange("A1:C1");
header.getFormat().getFont().setBold(true);
header.getFormat().getFill().setColor("E2F0E9");
header.getFormat().autofitColumns();
}
Your exact code will vary with the steps you took — that's expected and fine. The goal isn't to match this letter-for-letter; it's to recognize the pieces: a named routine, a range being selected, and the formatting actions you performed.
✅ Project Completion Checklist
- You recorded a macro (desktop) or Office Script (web) named
FormatHeaderRow - You ran it and saw the formatting apply automatically
- You opened the code and identified the bold and autofit lines
- You can explain when this automation is worth using vs doing it by hand
- On desktop, you saved the workbook as
.xlsmto keep the macro
🎯 Quick Quiz
Question 1: A coworker on Excel for the web says your .xlsm macro "does nothing" when they open it. Why?
Question 2: An unexpected spreadsheet arrives by email and insists you "Enable Content" to see the data. What's the right move?
📓 Learning Journal
Keep a learning journal as you work through this course — a separate document, a note, or even a second worksheet right in the workbook you're building. After each lesson, take a few minutes to write down:
- Key concepts you learned
- Techniques that clicked for you
- Questions or confusion points to revisit
- Ideas you want to try with your own data
- Your progress and feelings about learning this — including where your confidence grew
✍️ This lesson's prompt: Name one repetitive Excel task you do that passes the "repetitive, predictable, tedious" test — the same clicks every time. Would you automate it with VBA (desktop) or an Office Script (web), and why? How did it feel to read the code the recorder wrote — more approachable than you expected, or still intimidating? Be honest.
📝 Lesson Summary
🎓 Key Takeaways
- Automation records actions to replay them — worth it when a task is repetitive, predictable, and tedious, not for one-offs or judgment-heavy work.
- Macros/VBA use the macro recorder and live on the Developer tab in .xlsm files; VBA is deep but desktop-first (richest on Windows) and does not run on the web.
- Macro security matters: macro-enabled files are flagged, opening them shows an Enable Content prompt, and you should never enable macros in files you don't trust.
- Office Scripts are the modern, cloud automation — TypeScript on the Automate tab in Excel for the web — more portable because they're stored in the cloud, not baked into a file.
- Power Automate chains automation across apps, and Google Sheets' Apps Script is the close cousin of Office Scripts. This lesson is a taste, not a programming course.
🎉 What You've Accomplished
You recorded, ran, and read your first automation — and you understand the honest landscape around it: when automating is worth the effort, the classic VBA path and its desktop-only, security-conscious nature, and the modern cloud Office Scripts alternative. You can now spot a task worth automating and know which tool to reach for. That's a genuinely professional instinct, and you got it without needing to become a programmer.
❓ Common Questions
Do I need to learn to code to use macros?
No. The macro recorder (and the Office Scripts recorder) write the code for you as you perform the task by hand. You can record, run, and get real value without writing a line. Reading and lightly editing the recorded code is a natural next step if you want it — but it's optional. This lesson is a taste, not a coding course.
Should I use VBA or Office Scripts?
It depends on where you work. If you're on the Windows desktop and need deep, powerful, or legacy automation, VBA is the mature choice. If you work in Excel for the web, need automation that's portable across machines, or want to plug into Power Automate flows, Office Scripts is the modern fit. Excel's strength is that you have both options.
Are macros dangerous?
Macros you create in your own workbooks are perfectly safe and useful. The risk is running other
people's macro-enabled files. Excel flags .xlsm files and prompts before enabling content
for exactly this reason. The rule: never enable macros in a file you didn't create or don't fully trust —
especially unexpected email attachments. When in doubt, don't.
🔭 Looking Ahead
That wraps up Module 6 — you can now share, import/export, and automate. Next we move into the project modules, where everything comes together. In Lesson 7.1: Project — A Personal Budget & Finance Tracker, you'll build a complete, real budget workbook end to end — data, formulas, analysis, and a first taste of a dashboard — using the skills from the whole course so far.
✅ Before the Next Lesson
- Record and run at least one simple macro or Office Script, and read its code
- Decide whether VBA or Office Scripts fits your setup, and why
- Write your Learning Journal entry for this lesson
📚 Additional Resources
- Introduction to Office Scripts in Excel (Microsoft Support)
- Quick start: Create a macro & enable/disable macros — Microsoft Support
- Microsoft Power Automate — overview
🌟 Encouragement for the Journey
You just recorded a computer program without writing a line of code — and you understand honestly where it runs and how to stay safe. Most Excel users never peek behind this curtain; you have. That's the last building block of Module 6. Next, we put everything together into real projects, starting with a budget you'll actually use. 📊