vba Sleep Lib "kernel32" 给出 64 位系统错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41638504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sleep Lib "kernel32" gives 64-bit systems error
提问by John Tipton
I'm trying to close access (Application.Quit) after running all functions.
我试图Application.Quit在运行所有功能后关闭访问 ( )。
VBA close access after all functions finishedhas been a reference for me.
所有功能完成后的VBA关闭访问对我来说是一个参考。
but when I Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long), It's giving me the following error:
但是当我Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long),它给了我以下错误:
The code in this project must be updated for use on 64 bit systems.
必须更新此项目中的代码才能在 64 位系统上使用。
Is there any replacement of this code to do run all functions before completely closing access?
在完全关闭访问之前,是否可以替换此代码来运行所有功能?
回答by Comintern
The dwMillisecondsparameter is a DWORD, so it will technically be 32bit on a 32bit machine and 64bit on a 64bit machine. Because of this, it requires PtrSafenotation (although technically dwMillisecondswill marshal correctly because it's ByVal... and who wants to wait that long anyway) Change the declaration to this:
该dwMilliseconds参数是一个 DWORD,因此从技术上讲,它在 32 位机器上是 32 位,在 64 位机器上是 64 位。正因为如此,它需要PtrSafe符号(虽然从技术上讲dwMilliseconds会正确编组,因为它是ByVal......无论如何谁都想等那么久)将声明更改为:
#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
回答by cyboashu
change your api declaration to this :
将您的 api 声明更改为:
#If VBA7 And Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
For 64bit APIs read this: http://www.jkp-ads.com/articles/apideclarations.asp
对于 64 位 API,请阅读:http: //www.jkp-ads.com/articles/apideclarations.asp

