[VBA for Excel & Access] GetUserID fro Environment

5 views
Skip to first unread message

Rakesh Sharma

unread,
Aug 1, 2011, 6:52:59 AM8/1/11
to myvba...@googlegroups.com
---- Paste this in General section -----------
 
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
 
--- Copy this function and use it in your program ----------
 
Function getUserID() As String
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        getUserID = Left$(strUserName, lngLen - 1)
    Else
        getUserID = vbNullString
    End If
End Function


--
Posted By Rakesh Sharma to VBA for Excel & Access at 8/01/2011 04:22:00 PM
Reply all
Reply to author
Forward
0 new messages