Curious Minds

Clear answers to science and history questions

XLS Macro Tutorial: How to Record & Use Excel Macros

· 5 min read · Science

An XLS macro tutorial teaches you how to automate repetitive tasks in Excel by recording or writing small programs called macros, which are stored in Visual Basic for Applications (VBA) code inside a workbook. The fastest way to start is Excel's built-in Macro Recorder: you turn it on, perform your task once by hand, stop it, and Excel writes the VBA code for you, which you can then replay anytime with a single click or keyboard shortcut.

What a Macro Actually Is

A macro is a saved sequence of actions—typing, formatting, opening menus, running formulas—that Excel can replay on command. Under the hood, every macro is VBA code, a programming language embedded in Microsoft Excel and other Office applications. You never have to see that code if you don't want to: the recorder generates it automatically. But the code is always there, which is why macros only live in special file formats and why they behave differently from ordinary spreadsheet features.

The .xls versus .xlsm File Format Question

Older Excel files ending in .xls (the format used up to Excel 2003) can store macros by default, which is why people still search for an "xls macro tutorial." Modern Excel files ending in .xlsx deliberately cannot contain macros—it's a security measure. If you save a workbook containing a macro as .xlsx, Excel strips the macro out. To keep macros in a modern workbook, you must save in the .xlsm (macro-enabled workbook) format. So if your recorded macro vanished after saving, the file format is almost always the reason.

Step-by-Step: Recording Your First Macro

  1. Enable the Developer tab: go to File > Options > Customize Ribbon and check "Developer" (on Mac: Excel > Preferences > Ribbon & Toolbar).
  2. On the Developer tab, click Record Macro.
  3. Give the macro a name with no spaces (for example, FormatReport), optionally assign a shortcut key like Ctrl+Shift+F, and choose where to store it (see the next section).
  4. Click OK, then perform your task exactly once—select cells, apply formatting, insert a formula, whatever the routine is.
  5. Click Stop Recording on the Developer tab.
  6. Test it: reset your sheet, then run the macro from Developer > Macros or your shortcut key.

Two settings inside the Record Macro dialog matter a lot. "Use Relative References" makes the macro work wherever your cursor is, rather than always acting on the exact cells you clicked during recording. Absolute references are fine for fixed layouts; relative references are essential for macros you'll reuse across different rows or sheets.

Where Macros Are Stored

  • This workbook: the macro travels with the file. Best when the macro is specific to one spreadsheet or you'll share it with colleagues.
  • Personal Macro Workbook (PERSONAL.XLSB): a hidden workbook that opens with Excel on your machine. Best for macros you want available in every file, such as a favorite formatting routine. It only exists on your computer—it does not travel with workbooks you send to others.
  • New workbook: a scratch file for experiments; rarely what you want long-term.

Common Problems and Fixes

  • "Macros have been disabled" bar: Excel blocks macros in files from the internet or other computers by default. Click Enable Content only when you trust the file's source.
  • Macro disappeared after saving: you saved as .xlsx. Re-save as .xlsm.
  • Macro recorded but does the wrong thing: you recorded extra clicks or selections. Re-record, or open the VBA editor (Alt+F11) and delete the unneeded lines.
  • Macro always hits the same cells: you recorded with absolute references; re-record with Use Relative References turned on.
  • Shortcut key conflict: a key like Ctrl+C overrides Excel's own copy shortcut. Prefer Ctrl+Shift combinations.

Macro Security: What You Should Know

Because macros run real code, they have long been used to deliver malware, usually through email attachments. This is exactly why modern Excel disables them by default and why the .xlsx format forbids them. Sensible rules: never enable macros in a file you didn't expect to receive, keep your macro security settings at the default (disable with notification), and only lower security for specific trusted locations, not globally. Your own recorded macros are safe—the risk comes from other people's files.

From Recording to Writing VBA

The recorder has real limits: it can't make decisions ("if the total is negative, highlight it"), it can't loop, and it records every literal click you make. The natural next step is opening the VBA editor with Alt+F11, reading the code the recorder produced, and editing it. Recorded code is verbose but readable—keywords like Range, Selection, and Value map directly to what you did. Common beginner edits include changing a fixed range to a dynamic one, adding an If...Then block, or wrapping lines in a loop with For Each. Free references exist in Microsoft's VBA documentation, and countless recorded macros can be made reusable with just a few modified lines.

Alternatives When a Macro Is Overkill

Before automating with VBA, check whether a built-in feature already does the job: formulas, tables with calculated columns, conditional formatting, Power Query for repeated data cleanup, and Office Scripts (Microsoft's newer, JavaScript-based automation in Excel for the web) all cover many use cases without macro security concerns. Macros shine when the task involves genuinely repetitive multi-step actions that no formula or built-in tool handles.

Frequently Asked Questions

How do I enable macros in an Excel file?

When you open a macro-enabled file, a yellow security bar appears reading "SECURITY WARNING Macros have been disabled." Click Enable Content—but only if you know and trust where the file came from. If the bar doesn't appear and macros still won't run, check File > Options > Trust Center > Trust Center Settings > Macro Settings.

Can I run macros in Excel online or on a Mac?

Excel for the web does not run VBA macros at all; Microsoft's Office Scripts is the web alternative. Excel for the Mac does support VBA, including the recorder and editor, though some Windows-only code (for example, code that automates other applications) may not work.

Do I need to know programming to use macros?

No. The Macro Recorder lets complete beginners automate tasks without writing a single line of code. Programming knowledge only becomes useful when you want loops, decisions, or cleaner, reusable code—which you can learn gradually by editing recorded macros.

Why can't I save my file as .xlsx and keep the macro?

By design, the .xlsx format cannot contain macros—this separation is a security feature so that ordinary spreadsheets can never carry hidden code. Choose "Excel Macro-Enabled Workbook (*.xlsm)" in the Save As dialog instead.

How do I delete a macro?

Press Alt+F8 to open the Macros list, select the macro, and click Delete. For macros stored in the Personal Macro Workbook, you must first unhide it (Window > Unhide in the View tab) before it appears in the list.

In this article
  1. What a Macro Actually Is
  2. The .xls versus .xlsm File Format Question
  3. Step-by-Step: Recording Your First Macro
  4. Where Macros Are Stored
  5. Common Problems and Fixes
  6. Macro Security: What You Should Know
  7. From Recording to Writing VBA
  8. Alternatives When a Macro Is Overkill
  9. Frequently Asked Questions