VBA判断win操作系统是32位还是64位

利用API函数GetSystemWow64Directory看系统中是否存在SysWow64目录从而得到系统位数。在64位系统中,该函数返回SysWow64目录的路径字符串长度值。在32位系统中返回值为0.

代码:

#If VBA7 Then
    Private Declare PtrSafe Function GetSystemWow64Directory Lib "Kernel32.dll" Alias "GetSystemWow64DirectoryA" (ByVal lpBuffer As String, ByVal uSize As Long) As Long
#Else
    Private Declare Function GetSystemWow64Directory Lib "Kernel32.dll" Alias "GetSystemWow64DirectoryA" (ByVal lpBuffer As String, ByVal uSize As Long) As Long
#End If
    

Sub getOp()
Dim DirPath As String, Result As Long

DirPath = Space(255)
Result = GetSystemWow64Directory(DirPath, 255)

MsgBox IIf(Result <> 0, 64, 32) & "位操作系统"
End Sub

 

你可能感兴趣的:(vba,操作系统,位数,判断)