View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
GEP GEP is offline
external usenet poster
 
Posts: 2
Default How to get a user's user id in an Excel macro

Hutch, Thanks! The simple way worked great for me.

"Tom Hutchins" wrote:

The simplest way is
Dim UserName as string
UserName = Environ("USERNAME")

Here is another way to retrieve the user's LAN ID using an API call:

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

Function UserName() As String
Dim Buffer As String * 100
Dim BuffLen As Long
On Error GoTo UNerr
BuffLen = 100
GetUserName Buffer, BuffLen
UserName = Left(Buffer, BuffLen - 1)
Exit Function
UNerr:
UserName = vbNullString
End Function

You would call it like this:
Sub AAAAA()
MsgBox UserName()
End Sub

Finally, you could also try retrieving Application.UserName, which is the
name
entered on the Tools Options General tab.

Hope this helps,

Hutch

"GEP" wrote:

Is there a way for me to identify in an Excel macro the user id of the person
trying to execute the macro? For example, If User_ID = SmithJo Then (where
User_ID is something that Excel would make available to me somehow). I know
Excel knows user ids that users use to log into their PCs and/or network
since it displays them when I click on ToolsShared Workbook, for example.
Thanks!