Fix VBA Add-In Compatibility Problems in 64-Bit Word Builds
Question details
The user needs to resolve backward compatibility issues for a Word VBA add-in compiled in a newer 64-bit Office build that fails to run on older 64-bit builds.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Distributing a VBA add-in compiled in Word version 2508 or later to users running earlier 64-bit versions of Office.
- Observed behavior
- The VBA add-in fails to execute or compile in earlier 64-bit Office builds due to unexpected compiler, reference, ActiveX, or external library compatibility changes.
Before troubleshooting your VBA code, ensure you have access to environments running both the older and newer 64-bit versions of Office so you can properly test compilation and reproduce the errors.
Update Windows API Declarations and Types
Verify and update your VBA code to ensure all Windows API calls correctly declare 64-bit pointers and handles to prevent compilation failures.
Compatibility issues often arise when API calls are not properly formatted for the 64-bit architecture. You must ensure that 64-bit pointers and handles use the correct data types.
Launch Microsoft Word, open your macro-enabled document or template (.dotm), and press Alt + F11 to open the Visual Basic for Applications (VBA) Editor.
Search your modules for any Windows API 'Declare' statements. Insert the 'PtrSafe' keyword immediately after the 'Declare' keyword for every API call.
Change the data types for all pointers and handles from 'Long' to 'LongPtr' or 'LongLong'. This allows the compiler to handle 64-bit memory addresses correctly.
If the add-in must also run on 32-bit versions, wrap your API calls in conditional compilation blocks (e.g., #If VBA7 Then ... #Else ... #End If) to serve the correct declarations based on the Office architecture.

Compile in a Backward-Compatible Environment
Avoid newer compiler specificities by compiling the add-in on the oldest version of Office that you intend to support.
Inspect Project References and External Libraries
Check for broken or missing library references that may have been upgraded or deprecated in newer Office builds.
Experience Seamless Compatibility with WPS Office
Tired of dealing with Microsoft Office version fragmentations and unpredictable compiler errors? Switch to WPS Office, a highly compatible, lightweight, and free alternative that supports standard document formats without the versioning headaches.
- 1. Download WPS Office: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install the Software: Run the installer and follow the quick on-screen instructions to set up WPS Office on your computer.
- 3. Open Your Documents: Launch WPS Writer and open your existing .docx or .docm files directly to enjoy a seamless, highly compatible editing experience.

Frequently Asked Questions
What does 'Compile error in hidden module' mean?
This error usually indicates that VBA code within a protected or locked module is incompatible with the version, architecture (32-bit vs. 64-bit), or library references of the Office application currently running it.
Do I need to write completely separate code for 32-bit and 64-bit Office?
No. You can use conditional compilation blocks (such as #If Win64 Then or #If VBA7 Then) to maintain a single codebase. This ensures the correct Windows API data types (like LongPtr) are used based on the environment.
How do I edit the VBA code of a template directly without creating a new document?
Instead of double-clicking the .dotm file (which creates a new document based on the template), launch Microsoft Word, go to File > Open, and select the .dotm file. This opens the template itself, allowing you to edit and compile its underlying VBA code.




