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.

时间: 2024-10-31 06:44:01

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

Data Flow -&gt;&gt; Excel Connection遇到错误:[Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.....

在SSIS下做Excel导入数据的时候遇到下面的错误 [Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0209303. T

OK335xS canutils deal with compile error

/************************************************************************************** * OK335xS canutils deal with compile error * 声明: * 本文主要是记录解决编译can测试工具(canutils)时遇到的一些编译错误. * * 2015-9-4 晴 深圳 南山平山村 曾剑锋 *******************************************

Android source code compile error: “Try increasing heap size with java option &#39;-Xmx&lt;size&gt;&#39;”

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g" ./prebuilts/sdk/tools/jack-admin kill-server ./prebuilts/sdk/tools/jack-admin start-server Android source code compile error: "Try increasing heap size wi

IOS 编译错误,iOS compile error: no visible @interface for &#39;CDVCommandDelegateImpl&#39; declares the selector

把Cordova 升级到 3.6.3 版本后,在变异的使用出现了如下问题 The error: /Volumes/local.uhmuhm.net/projectxxx/htdocs/phonegap/src/Projectxxx/platforms/ios/Projectxxx/Classes/MainViewController.m:154:19: error: no visible @interface for 'CDVCommandDelegateImpl' declares the s

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 for this target Create new Android Virtual Device(AVD) 创建新的手机模拟器时,不能点OK完成, 提示如图中错误.是缺少相应的映象文件造成. 请在Android SDK Manager 里下载对应版本的 ARM EABI v7a System I

1.VBA教程 VBA Excel宏

Excel VBA宏 在这一章中,让我们了解如何编写一个简单的宏.让我们一步一步来. 第1步:首先,让我们能够在Excel20XX'开发'菜单.做同样的,点击 File >> Option. 第2步:点击自定义功能区选项卡,并选中“Developer”,然后点击“OK”. 第3步:在“Developer”带状出现在菜单栏. 第4步:点击“Visual Basic”按钮以打开VBA编辑器. 第5步:现在,让我们通过添加一个按钮,启动脚本.点击“Insert”>>选择“button”.

[vba]excel中求选中数据和为给定数所有的组合

昨天下午开始学习的vba,累死了,肯定有bug,待调试 vba程序如下: 1 Dim aSum As Integer 2 Dim tSum As Integer 3 Dim judge(30) As Integer 4 Dim arrMax As Integer 5 Dim arr 6 Dim location(30) As Integer 7 8 Function Test() 9 Dim arrWmax As Integer 10 Dim Rng As Range 11 Dim beginR

VBA Excel 对比两列数据

Sub Md() ' ' Macro1 Macro ' 宏由 BX 录制,时间: 2012-6-8 ' 宏中的列数可以输入 A - IV 也可以输入 1-256 ' Dim i%, j%, i1%, j1%, i2%, j2% myi = UCase(InputBox("第一列")) myj = UCase(InputBox("第二列")) ' '************************************ If myi Like "[A-Z]

the java.lang.UnsatisfiedLinkError: JD-Eclipse compile error

Start looking decompile tool that determines JD-Eclipse intends to use the online upgrade, sad destroy the machine does not , and led directly to enter the online update address can not find what plug-ins can be updated to the following, had to jdecl