How-To Guide

How to Convert XLS to XLSX Without Losing Macros (2026)

Sponsored
By Joshua Hall · April 15, 2026 · 8 min read
The blunt truth first: You cannot convert XLS to XLSX and keep macros. XLSX is defined by the ISO 29500 standard as a macro-free format. The correct move is to convert to XLSM — the macro-enabled sibling format. If someone tells you they can convert XLS to XLSX with macros intact, they are either wrong or renaming the file extension.

That said, "convert XLS to XLSX without losing macros" is one of the most-searched Excel questions, so let me give you the complete picture: what's technically happening, what your actual options are, and the exact steps that preserve every VBA module.

Why XLSX Cannot Contain Macros (The Technical Reason)

XLS is the legacy binary format (BIFF8) used by Excel 97–2003. It stores everything — worksheets, styles, and VBA — in a single binary blob using the Compound Document File Format.

When Microsoft introduced the OOXML format family in 2007, they split the file types by capability:

ExtensionFull NameMacros Allowed?Use Case
.xlsxExcel WorkbookNoData, charts, formulas — no code
.xlsmExcel Macro-Enabled WorkbookYesEverything + VBA modules
.xlsbExcel Binary WorkbookYesLarge files, VBA, fast open
.xlsExcel 97–2003 WorkbookYesLegacy compatibility

The XLSX specification (ISO 29500 Part 1) explicitly prohibits VBA storage. This isn't a tool limitation — it's a format specification. No tool can create a valid XLSX file that contains VBA macros. Any tool that claims to do so is either:

The Correct Conversion: XLS → XLSM

If you want to modernise your XLS files while keeping macros, the target format is .xlsm. Here are three ways to do it, from easiest to most automatable.

Method 1: Excel Desktop (Recommended for Single Files)

1 Open the .xls file in Excel (any version from 2007 onwards).
2 You'll see a yellow "Compatibility Mode" bar at the top. Ignore it for now.
3 Go to File → Save As.
4 In the "Save as type" dropdown, select Excel Macro-Enabled Workbook (*.xlsm). Do NOT select "Excel Workbook (*.xlsx)" — that drops your macros.
5 Click Save. Excel will confirm the format change.
6 Open the new .xlsm file. Open the VBA editor (Alt+F11). Verify all modules are present.
Verification step you must not skip: After saving as XLSM, open the VBA editor (Alt+F11) and count your modules. Compare this to the count in the original XLS. One-line modules that do nothing are often injected by legacy Excel — subtract those from your expected count.

Method 2: LibreOffice Command Line (Batch Conversion)

For batches of 10+ files, LibreOffice headless is reliable. It preserves VBA storage but marks macros as "from a potentially unsafe source" on first open in Excel — a one-time click-through per file.

libreoffice --headless --convert-to xlsm --outdir ./output/ *.xls

Caveats with LibreOffice:

Method 3: Python with openpyxl + xlrd (Programmatic, Advanced)

If you need to automate this as part of a pipeline, the cleanest approach is to extract macro bytes directly from the XLS binary and transplant them into a new XLSM container.

import xlrd
import zipfile
import shutil
import os

# This is a simplified illustration — full implementation requires VBA storage extraction
# which is available in the MacroKit technical guide

def extract_vba_storage(xls_path):
    """Extract the VBA Storage binary from an XLS file (Compound Document format)"""
    with open(xls_path, 'rb') as f:
        data = f.read()
    # VBA storage is identified by the signature at the Compound Document root
    # Full extraction logic: see MacroKit technical guide
    return data

def transplant_to_xlsm(xlsm_template, vba_bytes, output_path):
    """Inject VBA storage into an XLSM container"""
    shutil.copy(xlsm_template, output_path)
    with zipfile.ZipFile(output_path, 'a') as z:
        z.writestr('xl/vbaProject.bin', vba_bytes)

The full, tested implementation is in the MacroKit research kit — it handles edge cases including workbook protection, UserForm objects, and class modules.

What Online Converters Do to Your Macros

ToolXLS → XLSM Macro PreservationNotes
CloudConvertStrips macrosConverts via LibreOffice but exports XLSX, not XLSM
ZamzarStrips macrosNo XLSM output option
ILovePDFNot applicablePDF-focused, no XLSM output
Aspose.CellsPartialAPI supports XLSM output but requires paid licence for VBA
Excel DesktopFull preservationGold standard — see Method 1 above
LibreOffice headlessFull preservationMinor compatibility gaps for complex ActiveX
Watch out for this: Several online tools offer "XLS to XLSX" conversion and show a success message. The resulting file opens in Excel and looks correct — until someone tries to run the macros. The macros are gone. Excel doesn't warn you because the file format is valid; it just has no VBA.

Checking Your Macros After Conversion

Always run this three-step verification on converted files before you delete the originals:

1 Open the converted XLSM in Excel. Press Alt+F11 to open the VBA editor.
2 Count the modules in the Project Explorer (left panel). Compare against your original XLS.
3 Run the most critical macro in test mode — not on live data. If it executes without "Macro not found" or "Compile error", your conversion succeeded.
Free browser tool: The XLSM Macro Inspector shows every VBA module in any XLSM file and flags which ones risk being destroyed by specific converters. Run it on your converted file to confirm nothing is missing. No upload required — runs 100% in your browser.

Batch Conversion: 50+ Files

If you're migrating a library of XLS files — common when companies leave SharePoint 2010 or transition from on-premise Excel to Microsoft 365 — the LibreOffice command above scales cleanly to hundreds of files:

#!/bin/bash
# Batch convert all XLS in current directory to XLSM
mkdir -p ./xlsm-output
find . -maxdepth 1 -name "*.xls" | while read f; do
  echo "Converting: $f"
  libreoffice --headless --convert-to xlsm --outdir ./xlsm-output/ "$f"
done
echo "Done. Check ./xlsm-output/"

After batch conversion, run the XLSM Macro Inspector on a sample (10% of files) to verify macro preservation rates before deleting your originals.

FAQ

Can you convert XLS to XLSX without losing macros?

No — XLSX cannot contain macros by specification. Convert to XLSM instead. That is the correct modernisation path for any XLS file with VBA.

My IT department requires XLSX. What do I do?

Two options: (1) Keep the macros in a separate XLSM file and use Power Query to pull data into your XLSX reports. (2) Re-implement your macros as Python scripts or Power Automate flows that operate on XLSX files. Option 1 is faster; Option 2 is more future-proof.

Will my macros work after converting from XLS to XLSM?

In most cases, yes. The main compatibility issues are: (1) XLS-era API calls that were deprecated in Excel 2013+, (2) password-protected VBA projects (must be unprotected before conversion), (3) complex UserForm controls with embedded binary objects. Run your macros in test mode after conversion.

What if my colleague receives XLSM files and doesn't have macro-enabled Excel?

All modern Excel versions (2007+) open XLSM files. If they receive the file and see "Macros have been disabled", they need to click Enable Content once. The file format itself is not the issue — it's Excel's security settings per-machine.

Need to Migrate a Library of XLS Files?

The MacroKit research pack includes a complete migration checklist, the full Python implementation for batch VBA transplanting, and the keyword matrix for every XLSM/XLS conversion search query. $9 one-time.

Get MacroKit — $9 →
Related Articles
Why Converters Destroy Excel Macros XLSM to PDF: Keep Macros Excel Macro Migration Guide 2026 Best Excel Macro Converter Tools 2026