Insert user name in a cell

  • Does anyone know how can I insert the user name in an Excel cell?
    I have a Excel worksheet, that can be modified and printed by many users. How can it be done that the name of the user that is logged on to this sheet will always appear on the sheet, and on the printed page?

  • Re: Insert user name in a cell


    Welcome to the Ozgrid forum!

    Try the following to get the user name into cell A1. You can change the cell reference to suit your requirements.

    Sub Usernameincell()
    Range("A1").Value = Application.UserName
    End Sub


  • Re: Insert user name in a cell

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Range("a1").Value = Application.UserName
    End Sub

    should do it.

  • Re: Insert user name in a cell

    Or with API:

    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    private sub Test()
       dim strUser                As String * 50   
       dim lngDummy            as long
       lngDummy = GetUserName(strUser, 49)
       Range("a1").Value = strUser
    end sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!