User ID function


Posted by Bob Thuli on August 13, 2001 10:15 AM

Is there a formula that will give me the user ID? I would like to have the users ID on the print out. If there was a formula "info("user id")" that would be the formula I would want. Any help would be appreciated.

Posted by Russell Hauf on August 13, 2001 10:23 AM

Do you want the User's logon id, or their Excel/Office ID?

To get the Office UserName:

Application.UserName

If you want the User's logon ID, I believe you can find it in an earlier posting. Let me know if you need help finding it.

Russsell

Posted by faster on August 13, 2001 10:24 AM

This returns the Excel user name

Sub Test()
MsgBox Application.UserName
End Sub



Posted by tee on August 13, 2001 3:51 PM

Try this Function - it will return the User ID.

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

Function ReturnUserName() As String
' returns the NT Domain User Name
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen > 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnUserName = UCase(Trim(tString))
End Function


This Function will retun the User's Name.

Function ActiveUserName() As String
ActiveUserName = Application.UserName
End Function

Hope this helps.

Cheers
Tee