MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Auto Open Macro to test for a user ID

Posted by Kurt on August 09, 2000 8:53 AM

Hello all, I need an auto open macro to test for a user id.

Thanks in advance. This message board is great!


Posted by david on August 09, 0100 9:21 AM

user_details = Application.UserName
returns the userid in excel
I got a great one to find a logon name I can give you if you want.

Posted by Kurt on August 25, 0100 6:19 PM

Thanks! I appreciate your hard work.

Again Thanks David

Posted by David on August 09, 0100 10:39 PM

here it is as promised enjoy

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)
tString = rString
End If
On Error GoTo 0
ReturnUserName = UCase(Trim(tString))
End Function
Sub nameme()
Range("a1") = ReturnUserName()
End Sub