2

この 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
4

1 に答える 1