Excel Macro Workbook: What It Is and How to Use One

VBA & macros · Updated November 16, 2026

An Excel macro workbook is an Excel file that can store and run macros—sets of instructions that automate tasks, usually written in Visual Basic for Applications (VBA). In Microsoft 365 for Windows, its usual file extension is .xlsm; use that format when you need to keep VBA code in a workbook.

What an Excel macro workbook contains

A macro is a series of actions Excel can carry out for you. It might format a report, import and reshape data, create sheets, or repeat a calculation across many rows. A workbook with a macro can also contain ordinary worksheets, formulas, charts, tables, and other Excel content. The code and the spreadsheet data are related, but they are not the same thing: a macro changes or works with workbook content when it runs.

Most desktop Excel macros are written in VBA. You can write VBA yourself in the Visual Basic Editor, or use Excel’s macro recorder to capture certain actions and turn them into code. The recorder is useful for repetitive formatting and simple operations, but its output may include unnecessary steps and may rely on fixed cell selections. It is not a general-purpose recording of everything a person does in Excel.

A file ending in .xlsm is commonly called an Excel Macro-Enabled Workbook. The extension tells Excel that the file format can retain VBA projects. It does not mean that a macro will run automatically whenever the file opens. Excel’s security settings and the file’s source affect whether its macros are allowed to run.

How XLSM compares with other Excel formats

The format matters when you save or share a workbook. Choose based on what the file contains and how other people need to use it:

  • .xlsx is the standard Excel workbook format for spreadsheets that do not need to retain VBA macros. If you save a workbook containing VBA as .xlsx, Excel warns that the macro project will not be saved in that format.
  • .xlsm is the usual choice for a workbook that contains VBA macros. It supports regular spreadsheet content as well as the VBA project.
  • .xlsb is the Excel Binary Workbook format. It can also contain VBA, but it is a different format from .xlsm; use it only when its binary format suits your workflow and recipients.
  • .xltm is a macro-enabled Excel template. It is intended to create new workbooks based on a template that may include VBA.

Changing an extension by renaming the file in File Explorer does not convert its contents. Use Excel’s Save As command and select the intended file type. If you only need to share results and recipients do not need the code, you can provide a separate macro-free copy saved as .xlsx, after checking Excel’s warning and verifying the resulting workbook.

How macros work in Excel

VBA code is stored in a workbook’s macro project. A user can start a macro from Excel’s macro list, assign it to a button, or run it through other VBA code. Some workbooks use event procedures, which respond to events such as opening a workbook or changing a cell. An event procedure can run without the user choosing a macro from the list, which is one reason it is important to treat unfamiliar macro-enabled files cautiously.

A macro can read and change workbook data, apply formatting, create or delete sheets, and interact with other parts of the Office environment. Depending on its code and permissions, VBA can also access files or other resources. That flexibility makes macros useful for repetitive work, but it also means the code should be trusted before it is run. An .xlsm extension alone does not establish that a file is safe or that its code is reliable.

Create and save a macro-enabled workbook

In Excel for Microsoft 365 on Windows, you can create a macro in a new or existing workbook. First, show the Developer tab if it is not visible: select File > Options > Customize Ribbon, check Developer in the list of main tabs, and select OK. Then choose a method:

  • To record actions, select Developer > Code > Record Macro. Give the macro a name without spaces, choose where to store it, and select OK. Perform the actions you want captured, then select Developer > Code > Stop Recording. Review the result before relying on it, particularly if the macro will be used on different-sized data sets.
  • To write VBA, select Developer > Code > Visual Basic. In the Visual Basic Editor, select Insert > Module and enter a procedure in the module. Save the project as part of the workbook.

For example, this simple procedure formats the first row of the active worksheet as bold and adjusts the widths of columns in its used range. It assumes row 1 contains headings. Save a copy of the workbook before running a macro: macro actions cannot be undone with Ctrl+Z.

Sub FormatActiveSheet()
    Dim ws As Worksheet
    Dim dataRange As Range

    ' Work on the currently active worksheet.
    Set ws = ActiveSheet
    Set dataRange = ws.UsedRange

    ' Format row 1 as headings and fit used columns.
    ws.Rows(1).Font.Bold = True
    dataRange.Columns.AutoFit
End Sub

To save, select File > Save As, choose a location, open the file-type list, and select Excel Macro-Enabled Workbook (*.xlsm). If the workbook already contains VBA, Excel may prompt you when you choose a format that cannot retain it. Read that prompt rather than clicking through automatically.

Run a macro and understand Excel’s prompts

For a workbook you trust, select Developer > Code > Macros, choose the macro, and select Run. The macro list shows procedures that Excel makes available to run in that context; code used as an event procedure may not appear there. A button or another control can also be connected to a macro, so clicking a workbook control may run code.

Excel may show a security warning or block macros, especially when a file came from the internet or another untrusted location. Do not treat a warning as a routine obstacle to bypass. Confirm who supplied the file, why the macro is needed, and whether you can inspect or verify the code. If you are unsure, ask the sender for a macro-free version or for an explanation of the code’s purpose.

On Windows, macro settings are available through File > Options > Trust Center > Trust Center Settings > Macro Settings. The appropriate setting depends on your organization’s policy and the file’s source. Avoid enabling all macros globally just to open one workbook; that can allow code in other files to run as well. An organization may manage these settings centrally, so a user may not be able to change them.

Security and safe sharing

Macros are executable code, not merely spreadsheet formulas. A malicious macro can be designed to perform harmful actions, while a poorly written but legitimate macro can still overwrite data or produce incorrect results. Be especially cautious with unexpected attachments, files from unfamiliar websites, and workbooks that ask you to enable content without explaining why.

  • Get macro-enabled files from a source you can verify, and confirm an unexpected attachment with the sender through a separate channel.
  • Ask what the macro does and why the workbook needs it. If the purpose is only to view figures, request a macro-free copy.
  • Review code or have a knowledgeable person review it before running code from a source you do not already trust.
  • Keep an untouched backup before running a macro that changes data, and test the procedure on a copy of representative data first.
  • Follow your workplace’s security rules. Do not change Trust Center settings or move files to trusted locations just to suppress a warning unless your IT policy allows it.

VBA projects can also be password-protected, but that should not be treated as proof that a workbook is safe. Password protection is not a substitute for a trusted source, review, or a backup.

Excel for the web and Mac differences

Excel for the web can open and edit many workbooks that contain VBA, but it cannot create, run, or edit VBA macros. If the task depends on a macro, open the workbook in the Excel desktop application. Do not assume that a macro will run merely because the file opens in a browser.

Excel for Microsoft 365 for Mac supports VBA, but some Windows-specific features and integrations may not work the same way. The Developer tab can be enabled through Excel > Preferences > Ribbon & Toolbar in current Mac versions; labels and available options can vary by release. A workbook that depends on Windows-only controls, paths, or external components may need changes before it works on a Mac. Check the code and test on the platform where the workbook will be used.

Common problems and practical checks

If a macro does not run, the cause may be security policy, a disabled macro setting, an unsupported feature, or an error in the code. Check the exact warning, confirm the workbook’s file type, and verify that the macro is intended for the active workbook and sheet. If the code expects a sheet named Report but the actual tab has a different name, for instance, it may fail even though macros are enabled.

Another frequent problem is saving to the wrong format. If an Excel prompt says the workbook contains features that cannot be saved in the selected format, choosing to continue without those features can remove VBA. Return to Save As and choose .xlsm if the code must remain. If a macro works on one computer but not another, compare Excel versions, operating systems, references or add-ins the code uses, and the permissions available to each user.

Before distributing a macro workbook, test it with a copy of the intended input, confirm that its assumptions are clear, and tell recipients what it changes. For example, say whether it modifies the active sheet, expects a particular tab name, or replaces existing output. Clear instructions prevent users from running a valid macro in the wrong workbook or on the wrong data.

When a macro workbook is the right choice

Use .xlsm when a workflow genuinely benefits from VBA and the people using the file can run desktop Excel with suitable security permissions. It can be a practical choice for a recurring report that imports, formats, and arranges data in a consistent way. It may be a poor choice when recipients use Excel for the web, must not run code, or only need to read a finished report.

For simpler repeatable data-cleaning tasks, Power Query may be a better fit: it can record transformation steps and refresh them without relying on a VBA macro. Ordinary formulas, Excel tables, and built-in features such as sorting and filtering may be enough for many workbooks. The best option depends on the job, the users’ Excel environments, and the need to automate actions beyond what built-in tools can do.

Frequently Asked Questions

Is an XLSM file the same as an Excel macro workbook?
An .xlsm file is the standard Excel Macro-Enabled Workbook format, so people often use the terms interchangeably. The format can store VBA, although an individual XLSM file does not necessarily contain a useful macro.

Can I open an XLSM file without enabling macros?
Usually, you can open and inspect the workbook while leaving macros disabled, though some features may not work as intended. Do not enable code unless you trust the source and understand why it is needed.

Can Excel for the web run VBA macros?
No. Excel for the web can open many macro-enabled workbooks, but VBA macros cannot be created, edited, or run there. Use the desktop Excel application for VBA tasks.

What happens if I save an XLSM workbook as XLSX?
The XLSX format cannot retain VBA macro code. Excel warns that unsupported features may be removed; choose a macro-enabled format if the VBA must remain in the saved workbook.

Are Excel macros safe?
Some are legitimate automation, but macros are code and can make changes or access resources. Safety depends on the source and what the code does, so verify unfamiliar files and keep a backup before running a macro that edits data.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.