Getting Username from system in a cell

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,428
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.
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,428
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.
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
sorry didn't read your post.

You need to put the code in a Module and NOT the sheet code module.
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154

ADVERTISEMENT

edit: Oops, answered...
 

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,428
:( :( :(

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
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154

ADVERTISEMENT

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

Mark
 

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,428
THe new module is Module1. And, here is the code that I got in module:


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

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,428
:) :) :)

I got it this time guys.

Thanks a lot to all of you.
I really appreciate your help.
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
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 :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,553
Messages
5,596,807
Members
414,104
Latest member
imamalidadashzada

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
Top