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.
随机推荐
- BZOJ 4569: [Scoi2016]萌萌哒 [并查集 倍增]
传送门 题意:长为$n \le 10^5$的数字,给出$m \le 10^5$个限制$[l1,r1]\ [l2,r2]$两个子串完全相等,求方案数 把所有要求相等的位置连起来,不就是$9*10^{连通 ...
- Vim【学习笔记】
[2017-02-04] 先放几个比较好的资料,看这些资料就好了: 1.Vim入门基础 http://www.jianshu.com/p/bcbe916f97e1 2.vim配置 http://blo ...
- C#常用代码片段备忘
以下是从visual studio中整理出来的常用代码片段,以作备忘 快捷键: eh 用途: 类中事件实现函数模板 private void MyMethod(object sender, Event ...
- opencv-python与c++ opencv中的一些区别和基础的知识
使用opencv-python一段时间了,因为之前没有大量接触过c++下的opencv,在网上看c++的一些程序想改成python遇到了不少坑,正好在这里总结一下. 1.opencv 中x,y,hei ...
- txt文本文件记录日志
private static void Log(string content, string fileName="log.txt") { string logsPath = App ...
- [Python Study Notes]字符串操作
字符串操作 a.字符串格式化输出 name = "liu" print "i am %s " % name #输出: i am liu PS: 字符 ...
- 制作U盘Win10 PE
1.安装Windows ADK 下载地址 http://go.microsoft.com/fwlink/p/?LinkID=232339 2. 已管理员身份启动“部署和映像工具环境” 3.创建WinP ...
- 配置可以通过http协议访问的svn服务器
通过HTTP协议访问版本库是Subversion的亮点之一,这种方式具备许多svnserve服务器所没有的特性,使用上更加灵活. 关于mode_day_svn模块: 由于Subversion需要版本化 ...
- 存个emacs配置
emacs配置 (global-set-key [f9] 'compile-file) (global-set-key [f10] 'gud-gdb) (global-set-key (kbd &qu ...
- 关于echarts 报错 初始化对象未定义
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...