2
试图让此32位宏在Office 2010 64位上工作。我试着用PTRSAFE但无法得到它的工作.---新手在这个 感谢32位Excel宏与64位不兼容
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
我测试你的代码在64位和它为我工作。只要确保**命名范围Computer_Name **存在。 – Santosh 2013-05-13 14:41:23
或者,您可以使用'Environ $(“computername”)'获取计算机名称。 – Santosh 2013-05-13 14:44:04
@Invnet什么部分不起作用?你是否在特定的行上发生错误? – JMK 2013-05-13 14:45:44