64-bit Office VBA and Word instance close problem

Zhu, Ligong 280 Reputation points
2025-02-18T16:30:49.3933333+00:00

Hi,

We have a VBA application that works well in 32 bit office for years. Recently I made some VBA changes so that it can run in 64-bit office as well. Basically I added things like this:

#If VBA7 Then

**Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)**

#Else

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

#End If

and changes "Long" to "LongPtr" in all places.

After those code changes it works well in both 32-bit and 64 bit office in most functions except one place. In current code we close current Word instance only and leave a blank Word instance open in a function like this:

User's image

It still works well in 32-bit but in 64 bit it will close all Word instance for some reason.

When I tried to debug this issue in a 64-bit machine, all Word instance will close in two or three seconds after it stops at the very first breakpoint before it runs our VBA code:

User's image

This is the Word version we have:

Microsoft® Word for Microsoft 365 MSO (Version 2408 Build 16.0.17928.20336) 64-bit

I appreciate if you tell me how to fix this VBA problem in 64-bit office. We need to close only current Word instance in this function and leave a blank Word instance open.

Microsoft 365 and Office | Development | Other
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.