How to show current user name in a cell?

Anthony Kong picture Anthony Kong · Aug 4, 2011 · Viewed 237.8k times · Source

In most of the online resource I can find usually show me how to retrieve this information in VBA. Is there any direct way to get this information in a cell?

For example as simple as =ENVIRON('User') (which did not work)

Answer

Jon Egerton picture Jon Egerton · Aug 4, 2011

Based on the instructions at the link below, do the following.

In VBA insert a new module and paste in this code:

Public Function UserName()
    UserName = Environ$("UserName")
End Function

Call the function using the formula:

=Username()

Based on instructions at:

https://support.office.com/en-us/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f