试图让这个 32 位宏在 Office 2010 64 位上工作。我尝试使用 PTrSafe,但无法使其正常工作。---新手谢谢
Option Explicit
Private Declare Function fnGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetComputerName()
Dim strComputerName As String
Dim lngPos As Long
Const MAX_COMPUTERNAME_LENGTH = 100
Application.ScreenUpdating = False
strComputerName = String(MAX_COMPUTERNAME_LENGTH + 1, " ")
If fnGetComputerName(strComputerName, MAX_COMPUTERNAME_LENGTH) = 0 Then
strComputerName = "ErrorGettingComputerName"
Else
lngPos = InStr(1, strComputerName, Chr(0))
strComputerName = Left(strComputerName, lngPos - 1)
End If
GetComputerName = strComputerName
Application.Range("Computer_Name") = GetComputerName
Application.ScreenUpdating = True
End Function