excelvbaexcel-2003worksheet-function

How to show current user name in a cell?


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)


Solution

  • 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