Getting Username from system in a cell

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
I am trying to get the username from the system to display in A1 in a file in Excel. I got this code form internet and put it in the sheet by clicking right mouse on the sheet1 tab and view code and then pasted it there.

Function UserNameWindows() As String
UserNameWindows = Environ("USRNAME")
End Function

And then as per the instructions on the same page I inserted this formula in A1 : =UserNameWindows()

The person stated that by doing this, I should be able to get user name displayed in A1. BUt all it gives me is #NAME?.

Any help would be appreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I am still getting the same result. Infact, I had it the way you spelt it in the first place and then I saw in one of the posts on this forum that it has to be usrname for some reason. So I changed it to usrname.
Anyway, both are giving me the same result.
 
Upvote 0
:( :( :(

It is still the same old result. I must be an idiot not being able to do what is such a simple thing for you guys.
I inserted a new module and inserted the code in that module and then inserted the formula =UserNameWindows() in A1. It still is not working.

Could it be the formatting of cell in a particular way I need?

Please help
 
Upvote 0
You did use "username" this time, correct? BTW, don't take offense, as just checking... what did the system name the new module?

Mark
 
Upvote 0
THe new module is Module1. And, here is the code that I got in module:


Function UserNameWindows() As String
UserNameWindows = Environ("USERNAME")
End Function
 
Upvote 0
:) :) :)

I got it this time guys.

Thanks a lot to all of you.
I really appreciate your help.
 
Upvote 0
In a cell, general format, with your code as shown at #8 ---> =UserNameWindows() works just fine. Is there an err val in the cell?

Mark

Edit: Slow fingers on keyboard... Glad its working :)
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top