Consulting

Results 1 to 8 of 8

Thread: Populating A cell with the users name

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Populating A cell with the users name

    Does anyone know if it is possible to populate a cell with the users name from a network?

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    What I mean is can you pull the user name from the network and paste it into a cell?

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    I've used
    Application.UserName
    on a domain based NT network to get the users login name
    K :-)

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Thanks.. I'll Try it

  5. #5
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Application.Username gets the Applications default user name setup and not their loged on User name.

    There are many ways to get this...here is one


    Option Explicit
    
    Private Declare Function Get_User_Name _
        Lib "advapi32.dll" _
            Alias "GetUserNameA" ( _
                ByVal lpBuffer As String, _
                nSize As Long) _
    As Long
    
    Private Function NTUserName() As String
    '// Returns the NT login username
        Dim lpBuff As String * 25
        Get_User_Name lpBuff, 25
        NTUserName = Left(lpBuff, Len(lpBuff) - 1)
    End Function
    
    Private Function NetworkUsername()
    '// Returns the (Network) Username from the Environment variables
    Dim str As String
    Dim i As Integer
        i = 1
        '// looks for NWUSERNAME in environment variables
        Do Until Left(str, 10) = "NWUSERNAME"
            str = Environ$(i)
            i = i + 1
            If i > 255 Then Exit Do
        Loop
    If i < 255 Then
        '// Just cuts off the first 11 characters ("NWUSERNAME=")
        NetworkUsername = Right(str, Len(str) - 11)
    Else
        NetworkUsername = "No Network Name"
    End If
    End Function
    Kind Regards,
    Ivan F Moala From the City of Sails

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Austen,

    Another example, which doesn't require the API is in our Knowlege Base here

    This function can be used to pull either the MS Office username, Windows Login name or the Computer Name.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    kpuls -

    Thanks for the post. I incorporated this into a userform application.

    Again - Thanks,

    Kurt

  8. #8
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Cheers, Kurt! Glad you found it useful!

    Take care,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •