XLSX vs XLSM: What Happens to Macros When You Save or Convert
Explain macro parts, extension/content mismatch, signatures and safe migration.
How the Extension and Internal Content Type Must Agree
Every Office Open XML workbook—whether .xlsx, .xlsm, or .xlsb—uses the ZIP-based package structure defined by the Open Packaging Conventions. The file extension signals to the host application what to expect, but the actual contents are declared inside the package in [Content_Types].xml. A mismatch between the extension and the declared content type is the root cause of most “corrupt file” errors and silently missing macros.
- A valid
.xlsxfile must not contain a VBA project part. The[Content_Types].xmlmust omit any<Override>element forapplication/vnd.ms-office.vbaProject. - A valid
.xlsmfile must contain a VBA project part (typically stored asxl/vbaProject.bin) and must declare it in[Content_Types].xmlwith the content typeapplication/vnd.ms-office.vbaProject.
When you rename a .xlsm to .xlsx without altering the package internals, Excel reads the .xlsx extension, expects a macro-free workbook, finds the VBA project part, and blocks the file as invalid. Renaming a .xlsx to .xlsm produces the opposite condition: the extension promises macros, but no VBA project part exists. Excel opens the file but reports that it contains no macros. These behaviors are specified by the Office Open XML standard; the authoritative content-type registry and extension rules are in the primary technical reference.
What Each Format Physically Contains
The visual layer—cells, charts, pivot tables, conditional formatting—is identical between .xlsx and .xlsm. The difference is confined to the VBA storage parts.
| Package part | .xlsx |
.xlsm |
|---|---|---|
xl/workbook.xml |
Present | Present |
xl/vbaProject.bin |
Absent | Present |
xl/_rels/workbook.xml.rels |
No relationship to VBA project | Contains a relationship of type http://schemas.microsoft.com/office/2006/relationships/vbaProject |
[Content_Types].xml |
No VBA content type | Includes <Override PartName="/xl/vbaProject.bin" ContentType="application/vnd.ms-office.vbaProject"/> |
A viewer that does not implement VBA (Google Sheets, Apple Numbers, LibreOffice Calc without the VBA extension) will render the data but silently ignore xl/vbaProject.bin. The workbook opens without error, but no macro-driven automation executes.
Three Failure Modes with Diagnostic Steps
1. “The file is corrupt” After a Rename
A file originally saved as .xlsm is renamed to .xlsx to bypass an email filter or a file-size check. Excel opens the ZIP package, reads [Content_Types].xml, finds the VBA content type, and concludes the file violates the .xlsx specification.
Diagnostic step: Inspect the file with any ZIP utility. On macOS or Linux, run unzip -l renamed_file.xlsx | grep vbaProject. On Windows, open the file in 7-Zip and look for xl/vbaProject.bin. If the entry exists, the file is a misnamed .xlsm. Rename it back to .xlsm to restore normal operation. If you must deliver a .xlsx, remove the VBA project from the package first (see the migration steps below).
2. Macros Are Saved but Do Not Run
You save a workbook containing VBA code as .xlsx. Excel displays the warning: “The following features cannot be saved in a workbook without macro support: VB project.” If you click “Yes” to continue, Excel writes a .xlsx package with no VBA project part. The workbook looks intact, but the code is absent.
Diagnostic step: Open the saved .xlsx and press Alt+F11 to open the VBA editor. If the project explorer pane is empty, the macros were stripped during the save. You cannot recover them from the .xlsx file. The only recovery path is to locate a prior .xlsm version or a backup of the exported .bas files.
3. A .xlsm Opens in a Non-Excel Viewer Without Macros
This is expected behavior, not a failure. The VBA project is stored as a binary blob that only Excel and a limited set of compatible applications can parse. Google Sheets, Apple Numbers, and LibreOffice Calc (without the VBA extension) will render the data and formatting but ignore xl/vbaProject.bin. Any automation tied to buttons, event handlers, or custom functions will be absent.
Hard Limits of Conversion
- No VBA project in the source: If the original file never contained macros, saving it as
.xlsmproduces a valid macro-enabled container with no code inside. The extension alone does not create macros. - Excel Online and mobile apps: Microsoft’s web and mobile Excel clients cannot create, edit, or persist VBA projects. Saving a workbook from those platforms as
.xlsmmay produce a file with a correct extension but noxl/vbaProject.binpart. - Third-party converters: Tools that change the extension or repack the ZIP without updating
[Content_Types].xmland the relationship files produce broken files. Always verify the package contents after conversion using a ZIP listing.
Safe Migration: Moving Macros Without Breaking the File
From .xlsm to .xlsx (Remove Macros)
- Open the
.xlsmfile in the desktop version of Excel. - Press
Alt+F11to open the VBA editor. - In the Project Explorer, right-click each module, class, and userform and select Export File. Save each as a
.bas,.cls, or.frmfile for later reuse. - Close the VBA editor. Go to File → Save As and choose Excel Workbook (.xlsx). Excel will warn that the VB project will be removed. Click Yes.
- Verify the result: inspect the new
.xlsxwith a ZIP utility. The entryxl/vbaProject.binmust be absent.
From .xlsx to .xlsm (Add Macros)
- Open the
.xlsxfile in the desktop version of Excel. - Go to File → Save As and choose Excel Macro-Enabled Workbook (.xlsm). Excel adds the necessary content type and relationship scaffolding but does not yet create a VBA project.
- Press
Alt+F11to open the VBA editor. Add code directly or import previously exported.bas,.cls, and.frmfiles. - Save the
.xlsmfile. Excel writesxl/vbaProject.binand updates[Content_Types].xml. - Verify the result: inspect the
.xlsmwith a ZIP utility. The entryxl/vbaProject.binmust be present.
Command-Line Verification Before Distribution
# Check if a .xlsx contains a VBA project (should return nothing)
unzip -l file.xlsx | grep vbaProject
# Check if a .xlsm is missing its VBA project (should return a line)
unzip -l file.xlsm | grep vbaProject
On Windows, open the file in 7-Zip and navigate to the xl folder. The presence or absence of vbaProject.bin reveals the actual format regardless of extension.
Handling a Mismatched File You Receive
If someone sends you a file where the extension and internal content disagree, you have three options:
- Rename to the correct extension. If a ZIP listing shows
vbaProject.bininside a.xlsx, rename it to.xlsm. If a.xlsmlacksvbaProject.bin, rename it to.xlsx. Excel will re-validate the file on the next open. - Re-save from Excel. Open the file (Excel may warn of corruption; click Yes to attempt repair), then immediately use File → Save As and select the format that matches the internal content.
- Inspect the content type directly. Upload the file to xlsx.now and examine the raw
[Content_Types].xmlin the file structure viewer. If an<Override>element referencesvbaProject, the file is macro-enabled regardless of extension. You can download a corrected copy with the proper extension from the same tool.