File types · Explainer

The XLSM file (.xlsm)

An XLSM file is an Excel workbook that is allowed to contain macros: an XLSX-style ZIP of XML with room for a VBA project and Excel 4.0 macro sheets. This guide explains where the macros are stored, how it differs from XLSX and XLSB, how Excel decides whether macros run, and has free sample XLSM files, without macros, to download for testing.

At a glance

Full name
Excel Macro-Enabled Workbook
Extensions
.xlsm
MIME type
application/vnd.ms-excel.sheet.macroEnabled.12, registered with IANA by Microsoft in 2011
Kind
Binary: a ZIP package of XML parts (SpreadsheetML), plus an optional binary VBA project
Standard
Office Open XML (ECMA-376, ISO/IEC 29500) for the workbook; Microsoft's [MS-OFFMACRO2] and [MS-OVBA] for the macro parts
First released
2007, with Excel 2007, by Microsoft
Opens with
Excel (macros run on Windows and Mac), Excel for the web (macros kept but not run), LibreOffice Calc
Magic number
50 4B 03 04 ("PK"), the ZIP signature
Workbook content type
application/vnd.ms-excel.sheet.macroEnabled.main+xml
Macros
VBA in xl/vbaProject.bin; Excel 4.0 (XLM) macro sheets. Both optional
Sheet size
Same as XLSX: 1,048,576 rows by 16,384 columns

The basics

What is an XLSM file?

XLSM is Excel's format for workbooks that contain macros. A macro is a program stored in the workbook that automates work: importing a file every morning, cleaning up data, building a report, or adding buttons and forms. Excel's own macro language is VBA (Visual Basic for Applications); older workbooks may also use Excel 4.0 macros, known as XLM.

Since Excel 2007 the standard workbook, XLSX, can't hold macros. If you save a workbook that has VBA code or Excel 4.0 macro sheets, Excel asks you to choose the macro-enabled format instead. The separate extension exists so that people and security tools can see from the name that a workbook may contain code.

  • Same format, plus code. Sheets, formulas, charts and formatting are stored exactly as in an XLSX.
  • Macros are optional. The extension says the workbook may contain macros. Our samples don't.
  • Macros don't run by themselves. Excel's settings, Windows' Mark of the Web and your choices decide that.

Our samples contain no macros

Every XLSM on this page is the macro-enabled package type without a VBA project or macro sheet, so it's safe to open. olevba reports "No VBA or XLM macros found".

Anatomy

What's inside an XLSM file

An XLSM has the same structure as an XLSX: sheets, styles and properties as XML parts in a ZIP archive. This is sample-workbook.xlsm from the samples below, which has no macros, followed by what Excel adds when a workbook does have them.

sample-workbook.xlsm (structure)
sample-workbook.xlsm  (a ZIP archive, 7,277 bytes)
offset 0: 50 4B 03 04 …  "PK", a ZIP local file header

[Content_Types].xml          the type of every part
_rels/.rels                  where the workbook starts
docProps/app.xml             application properties
docProps/core.xml            title, author, "contains no macros"
xl/theme/theme1.xml          theme colours and fonts
xl/worksheets/sheet1.xml     sheet "Orders"
xl/worksheets/sheet2.xml     sheet "Summary"
xl/worksheets/sheet3.xml     sheet "About"
xl/styles.xml                number formats, fonts, fills
xl/workbook.xml              sheet names, the defined name OrderTotal
xl/_rels/workbook.xml.rels   links to sheets, styles, theme

In [Content_Types].xml:
<Override PartName="/xl/workbook.xml"
  ContentType="application/vnd.ms-excel.sheet.macroEnabled.main+xml"/>

A sheet formula, with its cached result:
<c r="C2" s="3"><f>SUMIF(Orders!$C$2:$C$9,A2,Orders!$F$2:$F$9)</f><v>63</v></c>

What Excel adds when a workbook HAS macros (not in this sample):
xl/vbaProject.bin            the VBA project
xl/_rels/workbook.xml.rels   + a relationship of type …/2006/relationships/vbaProject
xl/workbook.xml              <workbookPr codeName="ThisWorkbook"/>
xl/macrosheets/sheet1.xml    an Excel 4.0 (XLM) macro sheet, if there is one
  1. 150 4B 03 04

    The ZIP signature

    Identical to an XLSX. The first bytes can't tell you whether a workbook has macros.

  2. 2xl/worksheets/sheet1.xml

    Ordinary sheets

    Cells, formulas and formatting are stored exactly as in an XLSX. Nothing about the sheets changes when a workbook is macro-enabled.

  3. 3ContentType="application/vnd.ms-excel.sheet.macroEnabled.main+xml"

    The macro-enabled workbook type

    In an XLSX this says …spreadsheetml.sheet.main+xml. This value is what makes the package an XLSM, and Excel expects it to match the .xlsm extension.

  4. 4<f>SUMIF(…)</f><v>63</v>

    A formula is not a macro

    Formulas calculate values and can't change anything outside their cell. They work the same in XLSX and XLSM. Macros are programs that can edit the workbook, open files and, with VBA, call into Windows.

  5. 5xl/vbaProject.bin

    The VBA project (not in our sample)

    A binary OLE compound file holding the compressed VBA source of every module, as in a Word document. The workbook links to it with a vbaProject relationship.

  6. 6<workbookPr codeName="ThisWorkbook"/>

    Code names

    With VBA present, Excel gives the workbook and each sheet a code name (ThisWorkbook, Sheet1…), the names the VBA code uses to refer to them.

  7. 7xl/macrosheets/sheet1.xml

    Excel 4.0 macro sheets

    The older XLM macro language, from 1992, written as formulas on special sheets. They live outside vbaProject.bin, so a check that only looks for VBA misses them.

Under the hood

How an XLSM stores its macros

Three things separate an XLSM with macros from an XLSX:

  1. 1The content type of xl/workbook.xml in [Content_Types].xml is application/vnd.ms-excel.sheet.macroEnabled.main+xml. This is the only one that's always there.
  2. 2A VBA project, usually xl/vbaProject.bin, with content type application/vnd.ms-office.vbaProject. It's an OLE compound file, the container of the old XLS format, with a storage for the project and one compressed stream of source code per module, as [MS-OVBA] specifies. A signed project adds a signature part.
  3. 3Excel 4.0 macro sheets, if any, as their own parts next to the worksheets. They can be hidden, even "very hidden", like any sheet.

The VBA project also keeps compiled code for the Excel version that saved it. If that compiled code and the source disagree, a matching version of Excel may run code that isn't in the source you can read. Analysis tools such as olevba check for this mismatch, often called VBA stomping.

The extension has to match

Excel checks that the extension agrees with the workbook's content type. An XLSM renamed to .xlsx, or an XLSX package saved under .xlsm, is refused with "Excel cannot open the file because the file format or file extension is not valid". To drop the macros, save a copy as Excel Workbook (.xlsx) from Excel instead.

Comparison

XLSM vs XLSX, XLSB, XLS and XLTM

FormatMacrosStorageNotes
XLSXNoZIP of XMLThe default workbook. Excel removes macros if you save as XLSX.
XLSMYes, VBA and XLMZIP of XML plus a binary VBA partThe default choice when a workbook needs macros.
XLSBYesZIP of binary partsFaster to load and save for large workbooks. The extension doesn't tell you whether there are macros.
XLSYesOLE compound fileExcel 97 to 2003, 65,536 rows. The same extension with or without macros.
XLTMYesZIP of XML plus a binary VBA partA template: opening it creates a new workbook that inherits its macros.
XLAMYesZIP of XML plus a binary VBA partAn add-in: code that runs alongside every workbook while it's loaded.

If the people you send a workbook to only need the data, send an XLSX or a CSV. Use XLSM when the macros are part of what the workbook does.

Security

Will the macros run? Excel's security checks

Spreadsheets with macros have long been a favourite way to deliver malware, which is why Excel is careful with them. On Windows, a workbook with macros goes through these checks:

  • Protected View first. A workbook downloaded from the internet or opened from an email opens read-only until you choose Enable Editing.
  • Mark of the Web. Since 2022, Office on Windows blocks macros in files that Windows has marked as coming from the internet, and shows a red Security Risk banner with no option to enable them. Trusted Locations, signatures from trusted publishers and organisation policies are checked first; the DOCM page lists the order.
  • The usual warning. Workbooks without the mark show a yellow Security Warning bar with Enable Content.
  • Excel 4.0 macros are disabled by default in Microsoft 365, separately from VBA.

Excel for Mac, Excel on phones and tablets, and Excel for the web aren't affected by the 2022 change. Excel for the web never runs VBA: you can open and edit a workbook with macros there, and the macros stay in the file, but to run, view or delete them you need the desktop app.

A workbook that tells you to click Enable Content to "see the data" or "unlock" it is the classic trick. If you need the macros from a file you trust, unblock it in its file Properties rather than changing Excel's macro settings for everything.

Inspection

How to check an XLSM for macros without running them

  • Look in the package. unzip -l book.xlsm lists the parts. Look for vbaProject.bin and a macrosheets folder.
  • Run olevba from the free oletools package (pip install oletools). It extracts VBA code and detects Excel 4.0 macros in XLSM, XLSB and XLS files without running anything, and flags auto-run entry points such as Workbook_Open and Auto_Open.
  • In Excel, open the workbook with macros disabled and press Alt+F11 to see the VBA modules. Right-click the sheet tabs and choose Unhide to look for hidden macro sheets.
olevba on our featured sample
$ olevba sample-workbook.xlsm
olevba 0.60.2 on Python 3.13.16 - http://decalage.info/python/oletools
===============================================================================
FILE: sample-workbook.xlsm
Type: OpenXML
No VBA or XLM macros found.

How to

How to open, edit and convert an XLSM file

  • Excel on Windows and Mac opens, edits and runs XLSM workbooks. Show the Developer tab (File, Options, Customize Ribbon) to record and edit macros.
  • Excel for the web opens and edits the data and keeps the macros, but doesn't run them.
  • LibreOffice Calc opens XLSM files and can run some Excel VBA, under its own macro security settings.
  • Google Sheets imports the data and formulas; it doesn't run VBA.
  • Convert to XLSX: File, Save As, Excel Workbook (.xlsx). Excel warns that the VB project can't be saved in a macro-free workbook and leaves it out.
  • To CSV or PDF: Save As, or soffice --headless --convert-to pdf book.xlsm on a server. Macros don't run during the conversion.

Writing XLSM files with openpyxl

openpyxl writes the plain XLSX content type unless it loaded the file with keep_vba=True, whatever extension you save under. A workbook it saves as .xlsm without that option has an extension that doesn't match its content type, and Excel won't open it.

Troubleshooting

Common XLSM problems

  • "Microsoft has blocked macros from running because the source of this file is untrusted." The workbook came from the internet. If you trust it, close it, right-click the file, choose Properties, tick Unblock and open it again.
  • "The file format or file extension is not valid." The extension doesn't match the content inside: an XLSM renamed to .xlsx, a file saved by a tool that wrote the wrong content type, or a download that stopped part-way.
  • The macros are gone. The workbook was saved as XLSX, or edited by a program that doesn't keep VBA projects. Go back to the last .xlsm copy.
  • Buttons do nothing. Macros are disabled or blocked, or you're in Excel for the web or another spreadsheet app that doesn't run VBA.
  • Email or upload rejected. Many organisations block macro-enabled attachments. Share a link, or send an XLSX if the macros aren't needed.

Free downloads

Sample XLSM files to download

Free sample macro-enabled workbooks for testing upload filters, spreadsheet libraries and macro scanners. None of them contains macros: each is a valid XLSM package without a VBA project, safe to open. All were checked with unzip -t, openpyxl (keep_vba=True), a LibreOffice conversion to PDF and olevba.

sample-workbook.xlsm · 7.1 KBDownload

Browsers can't show this kind of file in a page. Download it to open it in the app it belongs to.

What's inside sample-workbook.xlsm

Browsers can't preview an XLSM, so download it and open it in Excel, LibreOffice or Google Sheets. Excel may show a security bar because of the file type, but there are no macros to enable.

  1. Orders sheet

    Eight fictional orders with text IDs that keep their leading zeros, dates, euro prices, =D2*E2 line totals and a SUM totals row. The header row is frozen.

  2. Summary sheet

    SUMIF formulas that total units and revenue per product across sheets.

  3. Cached results

    Every formula is stored with its result, as Excel does, so previews and libraries show numbers without recalculating.

  4. A defined name

    OrderTotal refers to the grand total cell, Orders!$F$10.

  5. About sheet and properties

    Text and document properties saying the file contains no macros, and how to check that yourself.

  6. No VBA project

    No xl/vbaProject.bin and no macro sheets: only the workbook's content type marks it as macro-enabled.

All sample XLSM files

  • Sample XLSM workbook (no macros)

    sample-workbook.xlsm · 7.1 KB (7,277 bytes)

    Three sheets: orders with formulas, a summary with SUMIF formulas, and an About sheet. Made with openpyxl, formula results filled in, then given the macro-enabled content type. Fictional data.

    • Testing previews and libraries with a real XLSM
    • Checking that a macro scanner reports a clean file
  • Minimal XLSM (5 parts)

    sample-minimal.xlsm · 1.6 KB (1,647 bytes)

    Written by hand with the same five parts as sample-minimal.xlsx on the XLSX page: content types, two relationship files, the workbook and one sheet. Only the workbook's content type and one cell's text differ.

    • Diffing the XLSX and XLSM content types
    • Testing parsers against the smallest valid XLSM
  • 100 KB XLSM file

    sample-100kb.xlsm · 100 KB (102,400 bytes)

    The featured workbook, padded to exactly 102,400 bytes with whitespace inside docProps/app.xml, stored uncompressed. No macros.

    • Upload limits with a macro-enabled type
    • Testing type-based upload filters

Ways to test with them

  • Upload filters: a filter that blocks macro-enabled workbooks by type should catch all three files. One that blocks only files with real macros should let them through, since none has a VBA project.
  • Libraries: openpyxl opens every file; saving one back as .xlsm keeps the macro-enabled content type only if you loaded it with keep_vba=True. Check what your own code writes.
  • Formula results: a previewer should show €208.20 in Orders!F10 and €63.00 in Summary!C2 of sample-workbook.xlsm without recalculating.
  • Content-type diff: compare [Content_Types].xml in sample-minimal.xlsm and sample-minimal.xlsx: only the workbook's ContentType differs.
  • Size limits: sample-100kb.xlsm is exactly 102,400 bytes.

Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.

Put it online

Have an XLSM file? Give it a link.

Drop a macro-enabled workbook on 99helpers and it gets its own web address. Visitors download the file and open it in Excel; because it came from the internet, Excel on Windows blocks its macros until they unblock it.

Questions

XLSM files, frequently asked

What is an XLSM file?

An Excel workbook that can contain macros, in VBA or the older Excel 4.0 language. Apart from the macros, it's stored exactly like an XLSX: a ZIP archive of XML files.

What's the difference between XLSX and XLSM?

XLSM can contain macros and XLSX can't. The content type of the workbook part differs, and an XLSM may hold a VBA project. Sheets, formulas and formatting are identical.

Is it safe to open an XLSM file?

Opening it is usually fine; enabling its macros is the risk. Only enable macros in workbooks you expected from someone you trust, and keep Office up to date.

How do I enable macros in an XLSM file?

Click Enable Content on the yellow Security Warning bar. If you see a red Security Risk banner instead, the file came from the internet: close it, open its Properties, tick Unblock, and open it again.

Can I rename an XLSM to XLSX?

No. Excel checks that the extension matches the content type and refuses the file. Open it and use Save As, Excel Workbook (.xlsx), which removes the macros.

Can I open an XLSM file without Excel?

Yes. LibreOffice Calc, Google Sheets and Excel for the web open the data. Excel for the web and Google Sheets don't run VBA macros.

Do macros work in Excel for the web?

No. You can open and edit a workbook with macros, and the macros stay in it, but to run or edit them you need the Excel desktop app.

How can I tell if an XLSM contains macros?

List its contents with unzip -l and look for vbaProject.bin or a macrosheets folder, or run olevba from oletools, which reports VBA and Excel 4.0 macros without running them.

Related formats

Other file types explained

Keep going

Related

Sources

Last reviewed 27 October 2026.