How to Update VBA File Dialog Code for 32-Bit and 64-Bit Project 2019
Question details
The user needs to modify existing VBA code that utilizes Windows API and OPENFILENAME structures so that the File Dialog functions correctly across 32-bit and 64-bit versions of Microsoft Project 2019.

- Product
- Microsoft Project 2019
- Device & OS
- Windows
- Scenario
- Upgrading Microsoft Project 2019 from a 32-bit to a 64-bit architecture while retaining older VBA macros.
- Observed behavior
- The VBA macro fails to open the File Dialog because the existing 32-bit Windows API declarations and memory structures are incompatible with the 64-bit application environment.
Before modifying your VBA code, verify whether you are running the 32-bit or 64-bit version of Microsoft Project 2019 (File > Account > About Project) and create a backup of your current project file.
Update API Declarations with PtrSafe and LongPtr
Modify your Windows API declarations to be compatible with 64-bit memory architecture by adding the PtrSafe keyword and updating pointer variables.
When migrating from 32-bit to 64-bit Office applications, API calls referencing external libraries like `comdlg32.dll` must use 64-bit compatible data types.
Using conditional compilation allows you to maintain a single VBA script that operates seamlessly on both 32-bit and 64-bit environments without throwing runtime errors.
Launch Microsoft Project 2019 and press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
Find the module containing the `Declare Function GetOpenFileName` and `Type OPENFILENAME` statements.
Wrap your declarations using `#If VBA7 Then` for modern Office versions and `#Else` for older versions to separate the logic.
In the `#If VBA7` section, add the `PtrSafe` keyword to your Declare statements (e.g., `Declare PtrSafe Function`). Change any handle or pointer data types (like `hwnd` or memory addresses) from `Long` to `LongPtr`.
Click 'Debug' in the top menu and select 'Compile VBAProject' to ensure there are no syntax errors, then save your code.

Consult Microsoft Q&A Forums for Complex Structures
Seek expert community assistance for properly defining the 64-bit OPENFILENAME structure if memory alignment errors persist.
Try WPS Office for a Highly Compatible Productivity Suite
If you frequently struggle with complex architecture upgrades and compatibility issues in heavy Office installations, consider switching to WPS Office. It provides a lightweight, highly compatible, and user-friendly alternative for your daily document, spreadsheet, and presentation needs.
- 1. Visit the WPS Website: Navigate to the official WPS Office website to access the latest version.
- 2. Download the Installer: Click the 'Free Download' button to safely download the lightweight installation package.
- 3. Install and Work: Run the installer, follow the simple on-screen prompts, and instantly begin opening or editing your Microsoft Office files.

Frequently Asked Questions
Why does my VBA File Dialog code stop working in 64-bit Project?
64-bit applications use 64-bit memory addresses. Older 32-bit Windows API declarations lack the required `PtrSafe` keyword and use 32-bit data types, causing the memory addresses to truncate and the code to fail.
What is the PtrSafe keyword in VBA?
`PtrSafe` is a VBA keyword introduced in VBA7 that asserts a Declare statement is safe to run in 64-bit versions of Office, telling the compiler that the API call has been updated for the 64-bit environment.
Can I write a single VBA macro that works on both 32-bit and 64-bit Office?
Yes, you can use conditional compilation blocks like `#If VBA7 Then ... #Else ... #End If` to define separate API declarations for 32-bit and 64-bit environments within the same macro.
What is LongPtr and when should I use it?
`LongPtr` is not a true data type, but a variable alias that resolves to a 32-bit integer (`Long`) in 32-bit Office and a 64-bit integer (`LongLong`) in 64-bit Office. You should use it for any variables representing pointers, memory addresses, or window handles.




