我有一个使用VB代码运行的excel,32版本看起来很好,现在当我在2016年办公室测试时,它给出了以下错误
必须更新此项目中的代码才能在64位系统上使用
由于我不擅长vb,因此我在更新代码方面遇到了问题。这是我的代码,以及如何更新它以实现64位兼容性,
Declare Function GetSystemDirectory Lib "kernel64" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
'a íÌÈ Ãí íßæä åäÇß ÌÏæá Úáì ÞÇÚÏÉ ÇáãÚáæãÇÊ ÈÅÓã
'a QtrDate
Global G_SystemPath As String
Function L_FileExist(L_FName As String) As Boolean
'a chick if the file given is found or not
'a input File Name
'a Output
'a True : if found
'a False : if not found
L_FileExist = Not (Trim(Dir(L_FName)) = "")
End Function
Public Function GetWindowsSysDir() As String
Dim strBuf As String
strBuf = Space$(250)
If GetSystemDirectory(strBuf, 250) Then
GetWindowsSysDir = StringFromBuffer(strBuf)
AddDirSep GetWindowsSysDir
End If
End Function
Public Function StringFromBuffer(Buffer As String) As String
Dim nPos As Long
nPos = InStr(Buffer, vbNullChar)
If nPos > 0 Then
StringFromBuffer = Left$(Buffer, nPos - 1)
Else
StringFromBuffer = Buffer
End If
End Function
Public Sub AddDirSep(strPathName As String)
strPathName = RTrim$(strPathName)
If Right$(strPathName, 1) <> "\" Then
strPathName = strPathName & "\"
End If
End Sub
Sub L_Secrit()
G_SystemPath = GetWindowsSysDir
If L_FileExist(G_SystemPath & "MSAYAR.DLL") Then
Sheet1.Cells(400, 2) = " "
Sheet1.Cells(401, 2) = " "
Sheet1.Cells(402, 2) = " "
答案 0 :(得分:1)
第一行应该是
#if VBA7 then
Declare PtrSafe Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
#else
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
#end if
这是一个nice resource来查找64位Win32API调用。