Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Hi,
I need to get the Windows logged in user name in the formula. Any hint how to get this? Thanks - Kedar Agarkar |
#2
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Thanks Pascal and Bob, shall be taking clues from your replies.
Thanks for your time. - Kedar |
#5
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.misc,microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Auto Updating the Logged in User | Excel Discussion (Misc queries) | |||
Creating an Excel Database for my Logged Time | Excel Worksheet Functions | |||
Sharing Problems- users keep reappearing even though logged out. | Excel Discussion (Misc queries) | |||
How do you reference the logged on user name in excel? | Excel Discussion (Misc queries) | |||
help with a formula (New User) | Excel Discussion (Misc queries) |