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. Vue脚手架(vue-cli)安装总结

    单页Web应用(single page web application,SPA),就是只有一张Web页面的应用,是加载单个HTML 页面并在用户与应用程序交互时动态更新该页面的Web应用程序. 提供一 ...

  2. C#常用代码片段备忘

    以下是从visual studio中整理出来的常用代码片段,以作备忘 快捷键: eh 用途: 类中事件实现函数模板 private void MyMethod(object sender, Event ...

  3. nodejs express搭建一个网站整理

    先前用安卓完成了一个优惠券搜索的app,发现在app上操作比较麻烦,于是决定弄个网页版的.做网站是自己的擅长的,毕竟毕业之后咱一直用asp.net mvc做网站也好几个年头了. 可是这次我又想换个方式 ...

  4. Python数据分析学习-re正则表达式模块

    正则表达式 为高级的文本模式匹配.抽取.与/或文本形式的搜索和替换功能提供了基础.简单地说,正则表达式(简称为 regex)是一些由字符和特殊符号组成的字符串,它们描述了模式的重复或者表述多个字符,于 ...

  5. Linux下LNMP启动不了的问题总结(2015.05)

    [1] *****@*****-VirtualBox:~$ sudo /etc/init.d/mysql.server start Starting MySQL * Couldn't find MyS ...

  6. 解决`向github提交代码是老要输入用户名密码`

    在命令行输入命令:git config --global credential.helper store☞ 这一步会在用户目录下的.gitconfig文件最后添加: [credential] help ...

  7. PPPoE拨号流程

    PPPoE(Point to Point Protocol over Ethernet,基于以太网的点对点协议)的工作流程包含发现(Discovery)和会话(Session)两个阶段,发现阶段是无状 ...

  8. C语言学习之插入排序

    此前的一些博文分别写了C语言中经典的排序方式,选择排序 冒泡排序 桶排序,此文就写 插入排序吧. 相对于冒泡排序,插入排序就比较方便快捷了.和冒泡 选择排序一样,插入排序也需要比较大小.可以这样理解插 ...

  9. java获取windows下面的文件对象

    import javax.swing.*;import javax.swing.filechooser.FileSystemView;import java.io.File; FileSystemVi ...

  10. ClientURL库-curl_setopt()

    这是一个出现得比较突兀的问题: 好好学习使用一下这个库:http://php.net/manual/zh/book.curl.php curl_setopt函数:curl_setopt - 设置一个c ...