![]() |
Getting Logged in User Name in formula...
Hi,
I need to get the Windows logged in user name in the formula. Any hint how to get this? Thanks - Kedar Agarkar |
Getting Logged in User Name in formula...
Hello Kedar Agarkar
You will need a little VBA to achieve this. Insert a new module into your workbook VBAProject and paste the following: Function GetUSerLogged() On Error Resume Next GetUSerLogged = CreateObject("WScript.Network").UserName If Err < 0 Then GetUSerLogged = "Not available" Err.Clear On Error GoTo 0: End If End Function Then in your spreadsheet, formulae: =GetUserLogged() HTH Cordially Pascal "Kedar Agarkar" a écrit dans le message de news: ... Hi, I need to get the Windows logged in user name in the formula. Any hint how to get this? Thanks - Kedar Agarkar |
Getting Logged in User Name in formula...
Msgbox Environ("Username")
-- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Kedar Agarkar" wrote in message ps.com... Hi, I need to get the Windows logged in user name in the formula. Any hint how to get this? Thanks - Kedar Agarkar |
Getting Logged in User Name in formula...
Thanks Pascal and Bob, shall be taking clues from your replies.
Thanks for your time. - Kedar |
Getting Logged in User Name in formula...
On Oct 29, 1:25 am, Kedar Agarkar wrote:
Hi, I need to get the Windows logged in user name in the formula. Any hint how to get this? Thanks - Kedar Agarkar Using API calls: Private Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function UserName() As String ' Returns the name of the logged-in user Dim Buffer As String * 100 Dim BuffLen As Long BuffLen = 100 GetUserName Buffer, BuffLen UserName = Left(Buffer, BuffLen - 1) End Function I got this from somewhere online. The usage is =PERSONAL.XLS! UserName() or =PERSONAL.XLSB!UserName(), depending on file format. |
Getting Logged in User Name in formula...
If it were me, I'd use papau's code, just changing the one line that uses the
Script object to use the Environ("username") [ GetUSerLogged = Environ("username") ] form that Bob Phillips provided. Environ is going to work on any Excel setup, whereas there's a possibility of failure with the script on some machines, plus scripting is external to Excel and is slower to return the result. papau's code slightly modified: Function GetUSerLogged() On Error Resume Next GetUSerLogged = Environ("username") If Err < 0 Then GetUSerLogged = "Not available" Err.Clear End If On Error GoTo 0 End Function "Kedar Agarkar" wrote: Thanks Pascal and Bob, shall be taking clues from your replies. Thanks for your time. - Kedar |
Getting Logged in User Name in formula...
In other words, if it were you you would use my code <bg?
-- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "JLatham" <HelpFrom @ Jlathamsite.com.(removethis) wrote in message ... If it were me, I'd use papau's code, just changing the one line that uses the Script object to use the Environ("username") [ GetUSerLogged = Environ("username") ] form that Bob Phillips provided. Environ is going to work on any Excel setup, whereas there's a possibility of failure with the script on some machines, plus scripting is external to Excel and is slower to return the result. papau's code slightly modified: Function GetUSerLogged() On Error Resume Next GetUSerLogged = Environ("username") If Err < 0 Then GetUSerLogged = "Not available" Err.Clear End If On Error GoTo 0 End Function "Kedar Agarkar" wrote: Thanks Pascal and Bob, shall be taking clues from your replies. Thanks for your time. - Kedar |
Getting Logged in User Name in formula...
That's pretty much the bottom line <g ... Your method of username retrieval
with the code segment papau set up to get it back to the user, even to including the error trapping for what should be an impossible error. "Bob Phillips" wrote: In other words, if it were you you would use my code <bg? -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "JLatham" <HelpFrom @ Jlathamsite.com.(removethis) wrote in message ... If it were me, I'd use papau's code, just changing the one line that uses the Script object to use the Environ("username") [ GetUSerLogged = Environ("username") ] form that Bob Phillips provided. Environ is going to work on any Excel setup, whereas there's a possibility of failure with the script on some machines, plus scripting is external to Excel and is slower to return the result. papau's code slightly modified: Function GetUSerLogged() On Error Resume Next GetUSerLogged = Environ("username") If Err < 0 Then GetUSerLogged = "Not available" Err.Clear End If On Error GoTo 0 End Function "Kedar Agarkar" wrote: Thanks Pascal and Bob, shall be taking clues from your replies. Thanks for your time. - Kedar |
Getting Logged in User Name in formula...
Actually, error trapping is not needed as Environ returns blank if the
variable isn't there. -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "JLatham" <HelpFrom @ Jlathamsite.com.(removethis) wrote in message ... That's pretty much the bottom line <g ... Your method of username retrieval with the code segment papau set up to get it back to the user, even to including the error trapping for what should be an impossible error. "Bob Phillips" wrote: In other words, if it were you you would use my code <bg? -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "JLatham" <HelpFrom @ Jlathamsite.com.(removethis) wrote in message ... If it were me, I'd use papau's code, just changing the one line that uses the Script object to use the Environ("username") [ GetUSerLogged = Environ("username") ] form that Bob Phillips provided. Environ is going to work on any Excel setup, whereas there's a possibility of failure with the script on some machines, plus scripting is external to Excel and is slower to return the result. papau's code slightly modified: Function GetUSerLogged() On Error Resume Next GetUSerLogged = Environ("username") If Err < 0 Then GetUSerLogged = "Not available" Err.Clear End If On Error GoTo 0 End Function "Kedar Agarkar" wrote: Thanks Pascal and Bob, shall be taking clues from your replies. Thanks for your time. - Kedar |
All times are GMT +1. The time now is 08:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com