VBA: how do I get full user name, not login ID?

mthompso

Board Regular
Joined
Apr 18, 2008
Messages
123
The following VBA code, executed on a Windows Network computer, will give me the Windows Login ID of the user that's logged in to the computer:
Code:
Sub UserName()
    MsgBox Environ("username")
End Sub

How do I get the full user name, not just the Windows Login ID?

Example: On this specific Windows network, the login id is the first letter of the user's first name followed by their last name. John Doe's login id is JDOE. How can I get VBA to give me the string "John Doe" and not "JDOE"?
 
Thank you very much! I was looking for a long time how to pull the username windows, and finally found! <3 <3 <3

I also just tried that and it worked... but it was very slow (3-4 seconds)

I also just ran MsgBox Application.UserName in the immediate window and it displayed my office user name straight away.

Maybe I'm misunderstanding the question, but Application.UserName seems to do exactly what I was looking for.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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