ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do i retrieve Windows User name on a excel sheet? (https://www.excelbanter.com/excel-discussion-misc-queries/209976-how-do-i-retrieve-windows-user-name-excel-sheet.html)

Sirigeri Goutam Shetty

How do i retrieve Windows User name on a excel sheet?
 
I'm trying to retrieve windows user name or log in name on a excel sheet with
certain commands. But i'm not sure if excel supports this feature.

Currently i'm using MS Office 2003 and WindowsXP professional edition.



Daniel.C[_2_]

How do i retrieve Windows User name on a excel sheet?
 
From the internet (www.mrexcel.com) :

Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Function

Sub test()
[A1] = GetUserName
End Sub

Daniel


I'm trying to retrieve windows user name or log in name on a excel sheet with
certain commands. But i'm not sure if excel supports this feature.

Currently i'm using MS Office 2003 and WindowsXP professional edition.




Luke M

How do i retrieve Windows User name on a excel sheet?
 
As clarification, Daniel's code needs to go in the VBA editor. Right click
the sheet tab, select view code, and then paste the code in.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Sirigeri Goutam Shetty" wrote:

I'm trying to retrieve windows user name or log in name on a excel sheet with
certain commands. But i'm not sure if excel supports this feature.

Currently i'm using MS Office 2003 and WindowsXP professional edition.



Mike H

How do i retrieve Windows User name on a excel sheet?
 
Just to clarify a little further, it doesn't all go there. This bit has to go
in a module in 'This Workbook'

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

Id go for something simpler.

Range("A1").Value = Environ("Username")

Mike



"Luke M" wrote:

As clarification, Daniel's code needs to go in the VBA editor. Right click
the sheet tab, select view code, and then paste the code in.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Sirigeri Goutam Shetty" wrote:

I'm trying to retrieve windows user name or log in name on a excel sheet with
certain commands. But i'm not sure if excel supports this feature.

Currently i'm using MS Office 2003 and WindowsXP professional edition.



Chip Pearson

How do i retrieve Windows User name on a excel sheet?
 
You can't do it directly from a formula -- you need VBA code. User

Function UserName() As String
UserName = Environ("UserName")
End Function

Then, call that function from a worksheet cell:

=UserName()

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 12 Nov 2008 05:00:02 -0800, Sirigeri Goutam Shetty <Sirigeri
Goutam wrote:

I'm trying to retrieve windows user name or log in name on a excel sheet with
certain commands. But i'm not sure if excel supports this feature.

Currently i'm using MS Office 2003 and WindowsXP professional edition.



All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com