Have you consulted Philipp Steifel's YouTube presentation and blog articles on this subject?
VBA Compile error when using #IF Win64 then Public Declare Sub Sleep Lib "kernel32"
This has been bugging me for a while now and I have been unable to resolve this compile error. I am running Windows 10 Enterprise 64bit. My version of Office is Microsoft 365 Apps for Enterprise. The issue is when I try to use the conditional directive to declare the sleep sub. I am getting the compile error below. I have tried using VBA7 and Win64 separately as well together as below with the same result. I created a blank module and placed only code below to duplicate the error.
For now I am commenting out the 32 bit line, but would like to find a way to resolve this. I appreciate any insights into this.
Microsoft 365 and Office | Access | For home | Windows
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
6 additional answers
Sort by: Most helpful
-
HansV 462.4K Reputation points MVP Volunteer Moderator2020-12-10T18:32:55+00:00 Use this instead:
#If VBA7 Then Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) #Else Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) #End If -
HansV 462.4K Reputation points MVP Volunteer Moderator2020-12-10T21:09:10+00:00 What happens if you simply ignore the error with the version I posted?
-
Anonymous
2020-12-10T21:36:07+00:00 I created a blank DB and new module with the code below. Even though I get the compile error when I paste or edit the directives, it will run the sub TestSleep without issue. The only thing I see is the 32bit line is colored in red. I don't have a 32 bit version to test with currently, but I suspect it will work as well.
Option Compare Database
Option Explicit
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub TestSleep()
Debug.Print "Before Sleep"
Sleep 100
Debug.Print "After Sleep"
End Sub
I'll watch the video you linked shortly.