2017-03-09 138 views
1

我有一個Excel用VB代碼運行,當我在辦公室2016測試似乎罰款32版本,現在它提供了以下錯誤如何使VBA代碼與64位Excel兼容?

此項目中的代碼必須使用可更新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

可能重複的[VBA代碼64位系統](http://stackoverflow.com/questions/26198994/vba-code-64-bit-systems) – Veve

回答

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位的Win32 API調用。

+0

我需要更改代碼中的其他任何東西。 – Bodhi

+0

更改此行將使API調用至少兼容。我不知道你的代碼是做什麼的,它是用來做什麼的。你爲什麼不試試並測試它? –

+0

是的..我測試它,它的工作很好..確實很有幫助。 – Bodhi