Access a user ID Windows NT


Posted by Graham on June 30, 2001 1:44 PM

I would like to put in a cell the user ID of the
person logged in under Windows NT.
I have seen other packages display the
Id and wondered is it possible to do it in Excel



Posted by Ivan F Moala on June 30, 2001 4:45 PM

Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function NTDomainUserName() As String
Dim strBuffer As String * 255
Dim lngBufferLength As Long
Dim lngRet As Long
Dim strTemp As String
Application.Volatile
lngBufferLength = 255
strBuffer = String(255, 0)
lngRet = GetUserName(strBuffer, lngBufferLength)
strTemp = (Left(strBuffer, lngBufferLength - 1))
NTDomainUserName = strTemp
End Function


HTH

Ivan