How to Convert .xls to .xlsx Without Losing Macros

January 21, 2026 · 8 min read

You've got an .xls workbook with years of VBA macros built into it — automation routines, custom functions, form controls that your team depends on every day. You know you need to move to the modern .xlsx format. You open Excel, click File → Save As, choose .xlsx, and hit save.

Excel shows a warning. You click OK. The file saves. Later, someone opens it and the macros are gone. Every last line of VBA code: deleted.

This happens constantly, and it's entirely preventable. Here's exactly what you need to know to convert your .xls files to a modern format without losing a single line of code.

The Trap: .xlsx Cannot Contain Macros

This is the single most important thing to understand before you start. The .xlsx format — the standard modern Excel format — cannot contain VBA macros by design. It's a security decision built into the Open XML specification.

When you save a macro-enabled .xls file as .xlsx, Excel will strip out every VBA module, every UserForm, every class module, and every macro-linked button. The warning dialog Microsoft shows is easy to dismiss without fully reading, and the damage is done silently.

Warning: Never save an .xls file with macros directly as .xlsx. You will lose all VBA code permanently unless you have a backup.

The correct format for a macro-enabled workbook in the modern era is .xlsm — the Excel Macro-Enabled Workbook format. It uses the same Open XML structure as .xlsx but includes a separate VBA project container that preserves your code.

Understanding the Three Formats

Format Era Contains Macros Notes
.xls Excel 97–2003 Yes (BIFF8) Legacy binary format. Limited to 65,536 rows.
.xlsx Excel 2007+ No Modern Open XML. 1M+ rows. No macros allowed.
.xlsm Excel 2007+ Yes Modern Open XML with VBA project. This is what you want.

The rule is straightforward: if your .xls file has macros, convert to .xlsm. If it has no macros, convert to .xlsx.

Step-by-Step: Converting a Single .xls File

Step 1: Check Whether Your File Actually Has Macros

Before converting, confirm what you're working with. Open the file in Excel and press Alt + F11 to open the VBA editor. In the Project Explorer on the left, look for:

If you see any of these, your file has macros and must be saved as .xlsm.

Step 2: Save As .xlsm (Not .xlsx)

  1. With the file open in Excel, go to File → Save As
  2. Choose your destination folder
  3. In the "Save as type" dropdown, select Excel Macro-Enabled Workbook (*.xlsm)
  4. Click Save

Excel will not warn you about macro loss when saving as .xlsm because the format supports them. The conversion is straightforward — your data, formulas, formatting, and VBA code all transfer cleanly.

Step 3: Verify the Conversion

After saving, close the file and reopen it from its new .xlsm location. Then:

  1. Press Alt + F11 and confirm all your modules are present
  2. Run a test macro to confirm it executes correctly
  3. Check that named ranges, pivot tables, and charts render correctly
  4. Scroll through each sheet and verify data looks right

Keep the original .xls file as a backup until you've fully validated the .xlsm version.

Converting many files at once?

LegacyLeaps scans your entire file collection, identifies every macro, and converts everything in one pass — preserving VBA code, formulas, and formatting.

Try the Free Scan

What Survives the Conversion — and What Doesn't

Generally Preserved

May Need Attention After Conversion

The Most Common Post-Conversion Problem: PtrSafe Errors

If your .xls file contains Win32 API declarations — calls to Windows DLLs using Declare Function or Declare Sub — you'll likely see a compile error after converting:

Compile error:
The code in this project must be updated for use on 64-bit systems.

This happens because the old 32-bit API declarations are incompatible with 64-bit Office. The fix is adding the PtrSafe keyword to each declaration:

' Old (32-bit only):
Declare Function GetTickCount Lib "kernel32" () As Long

' Fixed (works on both 32-bit and 64-bit):
Declare PtrSafe Function GetTickCount Lib "kernel32" () As LongPtr

Note two changes: PtrSafe is added after Declare, and the return type changes from Long to LongPtr for pointer-sized values. For a comprehensive walkthrough, see our guide on fixing PtrSafe errors after a Windows update.

Handling Large Batches of .xls Files

If you're dealing with dozens or hundreds of .xls files, manually opening each one in Excel isn't practical. A few options:

Option 1: PowerShell Script (Basic)

You can automate batch conversion using Excel's COM automation via PowerShell. This works for straightforward files:

$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $false

Get-ChildItem -Path "C:\Files" -Filter "*.xls" | ForEach-Object {
    $wb = $excel.Workbooks.Open($_.FullName)
    $newPath = $_.FullName -replace '\.xls$', '.xlsm'
    # xlOpenXMLWorkbookMacroEnabled = 52
    $wb.SaveAs($newPath, 52)
    $wb.Close()
}
$excel.Quit()

This approach has limits: it won't fix PtrSafe errors, won't audit what broke, and fails silently if a file has a password or corrupted structures.

Option 2: Dedicated Migration Tool

For files that contain complex VBA, ActiveX controls, or inter-file references, a dedicated migration tool handles the conversion more reliably. LegacyLeaps scans each file first, reports exactly which macros and controls it found, and converts everything in one pass. You see a compatibility report before anything is changed — so there are no surprises.

What About .xls Files Without Macros?

If your .xls files contain only data, formulas, and formatting — no VBA at all — you can safely convert to .xlsx directly. The process is identical: File → Save As → Excel Workbook (*.xlsx). No macros means no risk of macro loss.

Use the VBA editor check (Alt + F11) described above to confirm there's no code before choosing this path.

Frequently Asked Questions

My file was saved as .xlsx but my macros are gone — can I recover them?

Possibly, if you still have the original .xls file. The .xlsx file itself cannot contain VBA code — it was stripped out during the save. If you have the original, convert it to .xlsm as described above. If you don't have the original, recovery depends on whether any backup exists (previous versions in Windows, cloud storage, email attachments).

Will my macros run on other people's computers after conversion?

Yes, with the same requirements as before: the other machine needs Excel with macros enabled. Modern Excel defaults to blocking macros in files downloaded from the internet. Users either need to unblock the file via Properties → Unblock, or your organization needs to configure Trusted Locations.

Should I convert to .xlsm or keep using .xls?

Migrate to .xlsm. The .xls format is limited to 65,536 rows, uses a binary format that's harder to recover from corruption, and is increasingly flagged as a security risk by modern Office security policies. .xlsm gives you the full modern row limit, better compression, and compatibility with all current Excel features — while keeping your macros intact.

I have hundreds of .xls files. Do I need to convert all of them?

Start with the ones that are actively used. Dormant archives can stay as .xls until you need them. For active files, conversion to .xlsm reduces the risk of format-related issues from future Windows or Office updates.

Ready to migrate your .xls files?

Download LegacyLeaps and scan your files for free. You'll see exactly which macros, VBA code, and ActiveX controls were found — before converting anything.

Download Free Scanner

Get tips like this in your inbox

Practical fixes for legacy Excel and Access problems. No spam.

← Back to all posts