最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

64位Office代码不起作用

SEO心得admin66浏览0评论
本文介绍了64位Office代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我应该在64位系统上找出excel VBA代码兼容性问题。我不使用VB语言和下面的代码不是我的,但我必须解决这个问题。

Excel VB代码:

Option Explicit 私有声明函数WideCharToMultiByte Libkernel32.dll(ByVal CodePage As Long,ByVal dwFlags As Long,ByVal lpWideCharStr As Long,ByVal cchWideChar As Long,ByRef lpMultiByteStr As Byte,ByVal cchMultiByte As Long,ByVal lpDefaultChar As String,ByRef lpUsedDefaultChar As Long)As Long Private Const CP_UTF8 As Long = 65001 Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122& 公共函数ToUTF8(s as String)As Byte() 如果Len(s)= 0,则退出函数 Dim ccb As Long ccb = WideCharToMultiByte(CP_UTF8,0,StrPtr(s),Len(s),ByVal 0& 0,vbNullString,ByVal 0&) 如果ccb = 0然后 Err.Raise 5,内部错误。 End If Dim b()As Byte ReDim b(1 to ccb) 如果WideCharToMultiByte(CP_UTF8,0,StrPtr(s) ,Len(s),b(LBound(b)),ccb,vbNullString,ByVal 0&)= 0然后 Err.Raise 5,内部错误。 Else ToUTF8 = b 如果 结束函数

我试图添加条件#如果VBA7 和 PtrSave 到任何地方,但工作表仍然不工作。

这是我在Office 64位中尝试的代码

Option Explicit #如果VBA7然后私有声明PtrSafe函数WideCharToMultiByte Libkernel32(ByVal CodePage As Integer,ByVal dwFlags As Long,ByVal lpWideCharStr As LongPtr,ByVal cchWideChar As Long ,ByVal lpMultiByteStr As Long,ByVal cchMultiByte As LongPtr,ByVal lpDefaultChar As Long,ByVal lpUsedDefaultChar As Long)As LongPtr #Else 私有声明函数WideCharToMultiByte Libkernel32.dll(ByVal CodePage As Long,ByVal dwFlags As Long,ByVal lpWideCharStr As Long,ByVal cchWideChar As Long,ByRef lpMultiByteStr As Byte,ByVal cchMultiByte As Long,ByVal lpDefaultChar As String,ByRef lpUsedDefaultChar As Lon g)As Long #EndIf Private Const CP_UTF8 As Long = 65001 Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122& 公共函数ToUTF8(s as String)As Byte() 如果Len(s)= 0,则退出函数 Dim ccb As LongPtr ccb = WideCharToMultiByte(CP_UTF8,0,StrPtr(s),Len(s),ByVal 0& 0,vbNullString,ByVal 0&) 如果ccb = 0然后 Err.Raise 5,内部错误。 End If Dim b()As Byte ReDim b(1 to ccb)// ERROR TYPE MISMATCH on ccb 如果WideCharToMultiByte(CP_UTF8 ,0,StrPtr(s),Len(s),b(LBound(b)),ccb,vbNullString,ByVal 0&)= 0然后 Err.Raise 5,内部错误。 Else ToUTF8 = b 如果 结束函数

感谢您的帮助。

解决方案

(未验证)

更改

私有声明PtrSafe功能WideCharToMultiByte Libkernel32_ (ByVal CodePage As Integer,ByVal dwFlags As Long,ByVal lpWideCharStr _ As LongPtr,ByVal cchWideChar As Long,ByVal lpMultiByteStr As Long ,_ ByVal cchMultiByte As LongPtr,ByVal lpDefaultChar As Long,_ ByVal lpUsedDefaultChar As Long)As LongPtr

私有声明PtrSafe功能WideCharToMultiByte LibKernel32(_ ByVal CodePage As LongPtr,ByVal dwflags As LongPtr,_ ByVal lpWideCharStr As LongPtr,ByVal cchWideChar As LongPtr,_ ByVal lpMultiByteStr As LongPtr,ByVal cchMultiByte As LongPtr,_ ByVal lpDefaultChar As LongP tr,ByVal lpUsedDefaultChar As LongPtr)As LongPtr

Private Const CP_UTF8 As Long = 65001

私有Const CP_UTF8 = 65001

这个

code> Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122&

Private Const ERROR_INSUFFICIENT_BUFFER = 122&

这个

Dim ccb As LongPtr

/ p>

Dim ccb As Variant

在我建议的最后三个chnages中,我们将它们声明为Variants,因为我们不知道在不同系统上的类型。它将是 Long 或 LongPtr

I should figure out problem with excel VBA code compatibility on 64bit systems. I do not use VB language and code below is not my but I have to solve that issue.

Excel VB code:

Option Explicit Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Byte, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByRef lpUsedDefaultChar As Long) As Long Private Const CP_UTF8 As Long = 65001 Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122& Public Function ToUTF8(s As String) As Byte() If Len(s) = 0 Then Exit Function Dim ccb As Long ccb = WideCharToMultiByte(CP_UTF8, 0, StrPtr(s), Len(s), ByVal 0&, 0, vbNullString, ByVal 0&) If ccb = 0 Then Err.Raise 5, , "Internal error." End If Dim b() As Byte ReDim b(1 To ccb) If WideCharToMultiByte(CP_UTF8, 0, StrPtr(s), Len(s), b(LBound(b)), ccb, vbNullString, ByVal 0&) = 0 Then Err.Raise 5, , "Internal error." Else ToUTF8 = b End If End Function

I have tried to add conditions #If VBA7 and PtrSave to everywhere but worksheet still does not work.

This is the code that I tried in Office 64 Bit

Option Explicit #If VBA7 Then Private Declare PtrSafe Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Integer, ByVal dwFlags As Long, ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As LongPtr, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As LongPtr #Else Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Byte, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByRef lpUsedDefaultChar As Long) As Long #EndIf Private Const CP_UTF8 As Long = 65001 Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122& Public Function ToUTF8(s As String) As Byte() If Len(s) = 0 Then Exit Function Dim ccb As LongPtr ccb = WideCharToMultiByte(CP_UTF8, 0, StrPtr(s), Len(s), ByVal 0&, 0, vbNullString, ByVal 0&) If ccb = 0 Then Err.Raise 5, , "Internal error." End If Dim b() As Byte ReDim b(1 To ccb) // ERROR TYPE MISMATCH on ccb If WideCharToMultiByte(CP_UTF8, 0, StrPtr(s), Len(s), b(LBound(b)), ccb, vbNullString, ByVal 0&) = 0 Then Err.Raise 5, , "Internal error." Else ToUTF8 = b End If End Function

Thanks for help.

解决方案

(Untested)

Change

This

Private Declare PtrSafe Function WideCharToMultiByte Lib "kernel32" _ (ByVal CodePage As Integer, ByVal dwFlags As Long, ByVal lpWideCharStr _ As LongPtr, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, _ ByVal cchMultiByte As LongPtr, ByVal lpDefaultChar As Long, _ ByVal lpUsedDefaultChar As Long) As LongPtr

To

Private Declare PtrSafe Function WideCharToMultiByte Lib "Kernel32" ( _ ByVal CodePage As LongPtr, ByVal dwflags As LongPtr, _ ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As LongPtr, _ ByVal lpMultiByteStr As LongPtr, ByVal cchMultiByte As LongPtr, _ ByVal lpDefaultChar As LongPtr, ByVal lpUsedDefaultChar As LongPtr) As LongPtr

This

Private Const CP_UTF8 As Long = 65001

To

Private Const CP_UTF8 = 65001

This

Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122&

To

Private Const ERROR_INSUFFICIENT_BUFFER = 122&

This

Dim ccb As LongPtr

To

Dim ccb As Variant

In the last three chnages that I suggested, we are declaring them as Variants because we don't know what the type will be on different systems. It will either be Long or LongPtr

发布评论

评论列表(0)

  1. 暂无评论