in VBA

PtrSafe声明解决VBA从32位系统迁移到64位的‘Compile Error’问题

最近换了新的电脑,从32位系统升级到64位系统,以前有写一个VBA (Visual Basic Application)的程序,在32位的旧电脑上是可以使用的,但是在新的64位的系统上却有以下问题,

===
Compile error:

The code in this project must be update for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute.

见下图:

VBA error

解决方案:在所有出现问题的函数声明之前都加上PtrSafe,问题解决

例如:
原始为:

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

修改为:

Private Declare PtrSafe Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Write a Comment

Comment

5 + thirteen =