How to Fix Visual Basic and Excel 64-Bit Compatibility Errors
Question details
The user is experiencing VBA project corruption when saving and reopening an Excel macro file in 64-bit Office, while the same file functions normally on 32-bit Office setups.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Saving, closing, and reopening an existing VBA macro project within a 64-bit Office 2013 environment.
- Observed behavior
- The VBA project works initially but becomes corrupted upon reopening in the 64-bit version of Office, highlighting an architecture or file format compatibility conflict.
Before proceeding, identify whether your installed version of Excel is 32-bit or 64-bit by navigating to the File tab, selecting Account, and clicking 'About Excel' to view your architecture details.
Isolate the Issue Using a Minimal Sample File
Create a simplified version of your workbook to determine if the issue stems from specific VBA code, the file format, or the Office version architecture.
By moving your code to a clean, minimal file, you can rule out document-level corruption and pinpoint exactly which module or function is clashing with the 64-bit environment.
Open a new, blank workbook in Excel.
Press ALT + F11 to open the VBA Editor, and carefully copy only the specific macro code causing the issue into the new workbook.
Navigate to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' from the file format dropdown.
Open and execute this new file on both 32-bit and 64-bit versions of Excel. Note whether the corruption still occurs.
Update API Declarations for 64-Bit Compatibility
Modify Windows API calls in your VBA code to natively support 64-bit environments by utilizing the PtrSafe keyword and updated data types.
Try WPS Office for Seamless Macro and Spreadsheet Management
If you are struggling with Excel version compatibility and VBA corruption, consider trying WPS Office. It provides a lightweight, highly compatible environment for your spreadsheets with excellent support for standard macro functionalities, eliminating complex architecture conflicts.
- 1. Download and Install: Download WPS Office from the official website and follow the quick installation prompt.
- 2. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing .xlsm files directly.
- 3. Manage Macros Easily: Navigate to the Developer tab to access the built-in VBA editor and run your macros seamlessly.

Frequently Asked Questions
Why does my VBA code work perfectly in 32-bit Excel but crash in 64-bit?
64-bit Excel processes memory addresses using 64 bits instead of 32 bits. If your VBA code uses Windows API calls without the 'PtrSafe' keyword or relies on standard 'Long' data types instead of 'LongPtr' for memory pointers, the system cannot process the addresses correctly, leading to crashes or file corruption.
How do I check if my Excel installation is 32-bit or 64-bit?
Open Excel, click on the 'File' tab, and select 'Account' (or 'Help' in older versions). Click on the 'About Excel' button. The very top line of the resulting dialog box will explicitly state whether you are running a 32-bit or 64-bit installation.
Can I write VBA code that is compatible with both 32-bit and 64-bit Excel?
Yes. By using VBA compiler constants such as '#If VBA7 Then', you can write dual-compatible code. You provide the 64-bit 'PtrSafe' declarations in the first part of the 'If' statement and the legacy 32-bit declarations in the 'Else' section, allowing the macro to adapt based on the Excel version opening it.




