VBA Excel WideCharToMultiByte Compile error on 64-bit System
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的更多相关文章
- 一种简单有效的VBA源代码加密办法,支持64位宿主,适用于大部分VBA代码加密
原始出处:http://www.cnblogs.com/Charltsing/p/EncryptVBACode.html VBA代码加密是个老生常谈的问题,自从本人的VBA Dumper发布之后,在O ...
- 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 ...
- FreeModbus LINUXTCP Compile ERROR
/********************************************************************************* * FreeModbus LINU ...
- OK335xS canutils deal with compile error
/************************************************************************************** * OK335xS ca ...
- Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出
Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出 package com.test; import org.apach ...
- Handling CLIK AS3 Compile Error 1152 & 5000
Handling CLIK AS3 Compile Error 1152 & 5000 Action You add a CLIK AS3 component from CLIK_Compon ...
- 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 ...
- 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 ...
- 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.
随机推荐
- strcpy和strcat易忽略点
首先来看一段C程序: #include <stdio.h> #include <string.h> #include <stdlib.h> void GetMem( ...
- python基础dict,集合,文件
字典是一种key:value的数据类型dict1{ 'stud1':'孙礼昭', 'stud2':'slz', 'stud3':'sunlizhao',}dict是无序的,key是唯一的 天生去重增 ...
- WPF项目学习.一
WPF项目搭建 版权声明:本文为博主初学经验,未经博主允许不得转载. 一.前言 记录在学习与制作WPF过程中遇到的解决方案. 使用MVVM的优点是 数据和视图分离,双向绑定,低耦合,可重用行,相对独立 ...
- python数据分析工具包(1)——Numpy(一)
在本科阶段,我们常用的科学计算工具是MATLAB.下面介绍python的一个非常好用而且功能强大的科学计算库--Numpy. a powerful N-dimensional array object ...
- Redis 实践1- redis介绍和安装
redis是一个key-value存储系统,官方站点 http://redis.io 和memcached类似,但支持数据持久化 支持更多value类型,除了和string外,还支持hash.li ...
- php使用file_get_contents请求微信接口失败
windows下的php,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了.Linux下的PHP,就必须安装openssl模块,安装好了以后就 ...
- PV IP UV
PV(访问量) Page View,页面浏览量. 具体的说,就是在一天内,该网站的页面总共访问了多少次 IP(独立IP) 一天内访问网站的IP数量 UV(独立访客) Unique Visitor 一般 ...
- Java数字签名——DSA算法
RSA数字加密算法参考:http://www.cnblogs.com/LexMoon/p/javaRSA.html DSS: 数字签名标准 DSA: 数字签名算法 DSA仅仅包含数字签名 —————— ...
- 使用MyBatis集成阿里巴巴druid连接池(不使用spring)
在工作中发现mybatis默认的连接池POOLED,运行时间长了会报莫名其妙的连接失败错误.因此采用阿里巴巴的Druid数据源(码云链接 ,中文文档链接). mybatis更多数据源参考博客链接 . ...
- UVA - 1592 Database 枚举+map
思路 直接枚举两列,然后枚举每一行用map依次记录每对字符串出现的是否出现过(字符串最好先处理成数字,这样会更快),如果出现就是"NO",否则就是"YES". ...