How to Fix Excel 64-Bit Crashes with VBA and Visual Basic Errors
Question details
The user needs to resolve application crashes occurring in the 64-bit version of Excel when running or compiling VBA macros and Visual Basic code.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running, debugging, or compiling VBA macros that contain Windows API calls or interact with third-party add-ins in a 64-bit Excel environment.
- Observed behavior
- Excel unexpectedly crashes or force-closes due to incompatible 32-bit API declarations, unstable add-ins, or corrupted workbooks during VBA execution.
Before modifying your macro code or disabling add-ins, verify that both your Windows OS and Office suite are fully updated, and create a backup copy of your corrupted workbook.
Update VBA Declarations for 64-Bit Office
Legacy 32-bit VBA code using Windows API calls must be updated to be compatible with 64-bit Excel to prevent memory-related crashes.
When migrating workbooks from 32-bit to 64-bit Office, standard 'Declare' statements must be updated to include the 'PtrSafe' keyword. Additionally, data types that store pointers or memory handles must be changed from 'Long' to 'LongPtr'.
Launch Excel and press 'Alt + F11' on your keyboard to open the Visual Basic for Applications editor.
In the Project Explorer, double-click your modules to find any lines starting with 'Declare Function' or 'Declare Sub'.
Insert the 'PtrSafe' attribute immediately after the word 'Declare' (e.g., 'Declare PtrSafe Function').
Change the data types of arguments and return values that hold pointers or handles from 'Long' to 'LongPtr'.
Click 'Debug' in the top menu bar and select 'Compile VBAProject' to identify and fix any remaining architecture-related syntax errors.

Disable Unstable Add-Ins
Identify and disable incompatible or outdated third-party add-ins that might be conflicting with the VBA execution and triggering the crash.
Report Reproducible Crashes to Microsoft
If the workbook is clean and the VBA code is fully 64-bit compatible, the crash might be a native bug in the Excel build that needs to be reported.
Experience Stable Macros with WPS Office
If Microsoft Excel continues to crash due to environment or compatibility issues, consider switching to WPS Office. It provides a lightweight, highly compatible spreadsheet environment with robust support for VBA and macros, allowing you to run your scripts smoothly without heavy resource demands.
- 1. Download and Install: Get WPS Office from the official website and complete the quick installation.
- 2. Open Your Workbook: Launch WPS Spreadsheets and open your existing .xlsm or .xls file.
- 3. Enable Macros: Accept the security prompt to enable macros and safely execute your VBA code in the stable WPS environment.

Frequently Asked Questions
Why does my VBA code work on older Excel versions but crash on 64-bit Excel?
Older versions of Excel typically ran on 32-bit architecture. When moving to 64-bit Excel, any VBA code calling Windows APIs must be updated with the 'PtrSafe' keyword and 'LongPtr' variables; otherwise, memory mismanagement will cause Excel to crash abruptly.
Can corrupted workbooks cause Excel to crash during macro execution?
Yes. A corrupted file structure, hidden objects, or an overloaded cache can trigger sudden crashes when executing VBA. Copying your code, formatting, and data to a newly created workbook can often resolve underlying file-specific corruption.
Does the 64-bit version of Excel use a 32-bit Visual Basic editor?
No, this is a common misconception. The VBA environment included in 64-bit Office is also 64-bit (VBA7), which is precisely why strict memory pointer declarations are required to interface securely with the operating system.
How do I test if an Excel add-in is causing my VBA to crash?
Open Excel in Safe Mode by holding the 'Ctrl' key while launching the application or by running 'excel /safe' from the Windows Run dialog. If your macros run without crashing, the issue is likely caused by an incompatible or outdated third-party COM add-in.




