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

本文介绍了一种解决VBA程序在从32位系统升级到64位系统后出现的编译错误的方法。通过在函数声明前添加PtrSafe属性,可以更新项目以适应64位系统的需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近换了新的电脑,从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
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值