Compile Error:

The code in this project must be updated for use on64-bit systems.

Please review and update Declare statements and then mark them with the PtrSafe attribute.

1.问题:

32-bit的VBA程序,在64-bit系统上运行时,出现该编译错误。

环境:Office2010 Excel 64-bit, 64-bit Win7 OS

 

2.原因

原程序中,函数声明如下。该函数在32-bit系统中编译、运行没有问题。但是在64-bit系统中会出现编译错误。

Private Declare Function WideCharToMultiByte Lib "kernel32" _

(ByVal CodePage As Long, ByVal dwFlags As Long, lpWideCharStr As Integer, ByVal cchWideChar As Long, _

lpMultiByteStr As Byte, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long

 

3.修改

其实,提示信息中,已经说明的很清楚了。

只要在函数的声明处添加"PtrSafe"属性(无需修改其他地方),程序就正常了。

修改后程序:

Private Declare PtrSafe
Function WideCharToMultiByte Lib "kernel32" _

(ByVal CodePage As Long, ByVal dwFlags As Long, lpWideCharStr As Integer, ByVal cchWideChar As Long, _

lpMultiByteStr As Byte, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long

 

4.扩展

①PtrSafe<Keyword>

https://msdn.microsoft.com/en-us/library/office/gg278832.aspx?f=255&MSPPError=-2147217396

Declare statements with the PtrSafe keyword is the recommended syntax. Declare statements that include PtrSafe work correctly in the VBA7 development environment on both 32-bit and 64-bit platforms only after all data types in the Declare statement (parameters and return values) that need to store 64-bit quantities are updated to use LongLong for 64-bit integrals or LongPtr for pointers and handles. To ensure backwards compatibility with VBA version 6 and earlier use the following construct:

 

②LongPtr Data Type

https://msdn.microsoft.com/en-us/library/office/gg251378.aspx?f=255&MSPPError=-2147217396

LongPtr (Long integer on 32-bit systems, LongLong integer on 64-bit systems) variables are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647 on 32-bit systems; and signed 64-bit (8-byte) numbers ranging in value from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 on 64-bit systems.

VBA Excel WideCharToMultiByte Compile error on 64-bit System的更多相关文章

  1. 一种简单有效的VBA源代码加密办法,支持64位宿主,适用于大部分VBA代码加密

    原始出处:http://www.cnblogs.com/Charltsing/p/EncryptVBACode.html VBA代码加密是个老生常谈的问题,自从本人的VBA Dumper发布之后,在O ...

  2. Data Flow ->> Excel Connection遇到错误:[Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.....

    在SSIS下做Excel导入数据的时候遇到下面的错误 [Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONF ...

  3. FreeModbus LINUXTCP Compile ERROR

    /********************************************************************************* * FreeModbus LINU ...

  4. OK335xS canutils deal with compile error

    /************************************************************************************** * OK335xS ca ...

  5. Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出

    Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出 package com.test; import org.apach ...

  6. Handling CLIK AS3 Compile Error 1152 & 5000

    Handling CLIK AS3 Compile Error 1152 & 5000 Action You add a CLIK AS3 component from CLIK_Compon ...

  7. Android error:No CPU/ABI system image available for this target

    原文:Android error:No CPU/ABI system image available for this target No CPU/ABI system image available ...

  8. error: could not create '/System/Library/Frameworks/Python.framework/Versions/2.7/share': Operation not permitted

    参考: Python pip安装模块报错 Mac升级到EI Captain之后pip install 无法使用问题 error: could not create '/System/Library/F ...

  9. SecureCRT connecting VM Linux show error message: The remote system refused the connection.

    SecureCRT connecting VM Linux show error message: The remote system refused the connection.

随机推荐

  1. ctags的使用

    1. 生成tags文件 为当前目录下的所有C程序文件生成对应的tags文件: $ ctags *.c        为同一个目录下的所有文件建立tags如下 $ ctags –R (较常用) 这个命令 ...

  2. C#中内嵌资源的读取

    起因 作为一个从Cpper转到C#并且直接从事WPF开发的萌新来说,正式编码过程中碰到了不少问题,一路上磕磕碰碰的.因为软件设计需求上的要求,需要将一些配置文件(XML.INI等)内嵌到程序中,等需要 ...

  3. 自定义状态栏的颜色及navigation的title颜色

    1.在info.plist中添加View controller-based status bar appearance,值为NO 2.在设置状态栏的地方添加代码 [[UIApplication sha ...

  4. iOS 使用NTP时间同步服务

    githup上有相关开源库, ios-ntp 导入即可使用 NetworkClock *netClock = [NetworkClock sharedNetworkClock]; netClock.n ...

  5. Arbiter 系统使用说明

    Arbiter 系统使用说明 Overview Arbiter是NOI系列赛事的官方评测软件, 由北航的相关人员开发. 在OIer会经历的几场大型比赛中, 除了省选和PKUSC/THUSC不使用Arb ...

  6. ubuntu下安装memcached与php扩展测试使用

    1,memcached需要libevent,所以要先安装它 下载地址:http://download.chinaunix.net/download.php?id=45065&ResourceI ...

  7. ASP.NET Core的身份认证框架IdentityServer4--(2)API跟WEB端配置

    API配置 可以使用ASP.NET Core Web API模板.同样,我们建议您控制端口并使用与之前一样的方法来配置Kestrel和启动配置文件.端口配置为http://localhost:5001 ...

  8. npm注意事项(附带Vue-cli安装)

    下载完nodeJS后,可选择更改配置目录 1.npm config set prefix "D:\node\node-global"<!--配置全局安装目录--> 2. ...

  9. java-redis集合数据操作示例(三)

    redis系列博文,redis连接管理类的代码请跳转查看<java-redis字符类数据操作示例(一)>. 一.集合类型缓存测试类 public class SetTest { /** * ...

  10. iterator的romove方法的注意事项

    package cn.lonecloud.Iterator; import java.util.ArrayList; import java.util.Iterator; public class m ...