Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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! |
#2
![]() |
|||
|
|||
![]() Formula:
__________________
I am not human. I am an Excel Wizard |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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! |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel Macro: Pause & ask user: "Are you sure you want to continue? | Excel Discussion (Misc queries) | |||
Excel home and student user's manual? | Excel Discussion (Misc queries) | |||
How can second, third user sign excel file containing macro | Excel Discussion (Misc queries) | |||
Macro Error when moved Xcel Sheets from User's Home Dir to Networ | New Users to Excel | |||
New Excel user needs help with simple Macro... | New Users to Excel |