Troubleshoot VBA Code Disappearing in Excel XLSM Files
Question details
The user needs to diagnose Excel macro-enabled XLSM files where VBA code appears to disappear, workbooks crash, or macros run much more slowly than expected.

- Product
- Microsoft Excel for Microsoft 365
- Device & OS
- not provided
- Scenario
- Opening, repairing, and running VBA macros in multiple macro-enabled tracking workbooks that use buttons and UserForms.
- Observed behavior
- Some XLSM files crash when opened or when a button or UserForm is used. VBA code may appear to be missing, and previously fast macros may take several seconds to run.
Work from a local copy of the affected XLSM workbook rather than a network share or synced folder. Note the Excel version and build number, the exact error message, and whether the problem began after a Microsoft 365 update.
Test the XLSM file locally and isolate macro security or add-in conflicts
Use this method when the workbook opens inconsistently, macros are blocked, or crashes occur when buttons or UserForms run.
Testing in a trusted local folder helps distinguish workbook damage from network, synchronization, security, or add-in issues. Enable macros only for files and locations that you trust.
Copy the affected .xlsm file to a local folder such as Documents, then open the local copy in Excel instead of opening it from a network drive, email attachment, or cloud-synced location.
In Excel, select File > Options > Trust Center > Trust Center Settings > Macro Settings. Review the selected macro setting, then use Trusted Locations to add only a secure local test folder if your organization permits it.
Select File > Options > Add-ins. At the bottom, choose Excel Add-ins or COM Add-ins from the Manage list, select Go, clear add-ins temporarily, and restart Excel. Re-enable them one at a time to identify a conflict.
Open the same local test copy on another computer with Excel. If it works there, compare Excel build numbers, installed add-ins, antivirus controls, and permissions between the two computers.

Use Open and Repair and restore the VBA project from a known-good copy
Use this method when an XLSM workbook will not open correctly, crashes repeatedly, or shows signs of file corruption.
Review Microsoft 365 updates when macro performance changed suddenly
Use this method when unchanged VBA code becomes slow or failures began after a particular Microsoft 365 build.
Use WPS Office for everyday XLSM workbook access and spreadsheet work
If Microsoft Excel stability or update behavior is disrupting routine spreadsheet work, WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and seamless migration for common Office documents. WPS Spreadsheets can open and edit Excel-format workbooks, helping teams continue standard worksheet tasks while Microsoft-specific VBA issues are investigated.

Frequently Asked Questions
Can Excel Open and Repair restore VBA code that has disappeared?
Open and Repair may repair workbook structure and allow an XLSM file to open, but it cannot reliably reconstruct deleted or corrupted VBA project content. Open the repaired file with Alt+F11 and restore missing modules or UserForms from a known-good copy when available.
Why do XLSM files work locally but fail on a network drive?
Network interruptions, sync conflicts, permissions, or security policies can affect how an XLSM file is opened and saved. Copy the file to a local folder for testing, then check the network location, access permissions, and synchronization software if the local copy works.
Where can I check whether Excel is blocking macros?
In Excel, go to File > Options > Trust Center > Trust Center Settings > Macro Settings. You can also review File > Options > Trust Center > Trust Center Settings > Trusted Locations for approved local folders.
How do I determine whether an Excel add-in is causing a VBA crash?
Go to File > Options > Add-ins, choose COM Add-ins or Excel Add-ins in the Manage box, then select Go. Disable all add-ins, restart Excel, and re-enable them individually while testing the affected workbook.
What information should I send to Microsoft Support for an XLSM crash?
Include the Excel version and build from File > Account > About Excel, the crash or error details, the time the problem started, installed add-ins, whether the file is local or network-based, and the smallest reproducible XLSM sample or set of steps.




