Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

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

Check out our Excel VBA Resources

Re: Access a user ID Windows NT

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


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.