logo
search
VBA & Macro Problems

How to Fix Excel 64-Bit Crashes with VBA and Visual Basic Errors

Olivia MillerOlivia Miller Oct 21, 2026 868 views

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.

How to Fix Excel 64-Bit Crashes with VBA and Visual Basic Errors
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 you start

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.

Solution 1Recommended

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'.

1
Open the VBA Editor

Launch Excel and press 'Alt + F11' on your keyboard to open the Visual Basic for Applications editor.

2
Locate API Declarations

In the Project Explorer, double-click your modules to find any lines starting with 'Declare Function' or 'Declare Sub'.

3
Add the PtrSafe Keyword

Insert the 'PtrSafe' attribute immediately after the word 'Declare' (e.g., 'Declare PtrSafe Function').

4
Update Variables to LongPtr

Change the data types of arguments and return values that hold pointers or handles from 'Long' to 'LongPtr'.

5
Compile the VBA Project

Click 'Debug' in the top menu bar and select 'Compile VBAProject' to identify and fix any remaining architecture-related syntax errors.

Update VBA Declarations for 64-Bit Office
API Compatibility: Using conditional compilation block (#If VBA7 Then) allows your macro to run smoothly on both 32-bit and 64-bit versions of Office without throwing syntax errors.
Free Microsoft Office alternative

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. 1. Download and Install: Get WPS Office from the official website and complete the quick installation.
  2. 2. Open Your Workbook: Launch WPS Spreadsheets and open your existing .xlsm or .xls file.
  3. 3. Enable Macros: Accept the security prompt to enable macros and safely execute your VBA code in the stable WPS environment.
High compatibility with Microsoft Excel macro formats (.xlsm, .xlsb, .xlsx)Built-in VBA editor for running, debugging, and editing macros seamlesslyLightweight software architecture ensuring fast loading and stable performanceFree and intuitive interface that mimics familiar Office layouts for easy migration
microsoft office alternative - wps office

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.