VBA & Macro Problems

How to Update VBA File Dialog Code for 32-Bit and 64-Bit Project 2019

Emma BrownEmma Brown Nov 3, 2026 870 views

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.

Update VBA File Dialog Code for 32-Bit and 64-Bit 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 you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Launch Microsoft Project 2019 and press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

2
Locate Existing API Declarations

Find the module containing the `Declare Function GetOpenFileName` and `Type OPENFILENAME` statements.

3
Apply Conditional Compilation

Wrap your declarations using `#If VBA7 Then` for modern Office versions and `#Else` for older versions to separate the logic.

4
Add PtrSafe and Update Data Types

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

5
Compile and Save

Click 'Debug' in the top menu and select 'Compile VBAProject' to ensure there are no syntax errors, then save your code.

Update API Declarations with PtrSafe and LongPtr
Compatibility Confirmed: Using the LongPtr data type ensures your variables dynamically scale to 32-bit or 64-bit integers depending on the host application architecture.
Free Microsoft Office alternative

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. 1. Visit the WPS Website: Navigate to the official WPS Office website to access the latest version.
  2. 2. Download the Installer: Click the 'Free Download' button to safely download the lightweight installation package.
  3. 3. Install and Work: Run the installer, follow the simple on-screen prompts, and instantly begin opening or editing your Microsoft Office files.
Fully compatible with standard Microsoft Office formats including XLSX, DOCX, and PPTX.Pro version includes robust support for standard VBA and Macros.Extremely lightweight installation with fast startup times and low memory usage.Familiar tabbed user interface makes migrating effortless.
microsoft office alternative - wps office

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.