CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2001
    Posts
    2

    Picking up currently logged in user name with VBA

    I need a way to pick up the name the currently logged in user. The OS is windows NT 4 and the code will form part of an Excel module. It doesn't matter where the name comes from, if someone has a way of extracting the information from the registry I can adapt the code to suite my system. Thanks in advance.


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Picking up currently logged in user name with VBA

    This will do the job

    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (byval
    lpBuffer as string, nSize as Long) as Long

    Function GetUser() as string

    Dim lpUserID as string
    Dim nBuffer as Long
    Dim Ret as Long
    lpUserID = string(25, 0)
    nBuffer = 25
    Ret = GetUserName(lpUserID, nBuffer)

    If Ret <> 0 then
    GetUser = lpUserID
    End If

    End Function




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Aug 2001
    Posts
    4

    Re: Picking up currently logged in user name with VBA

    Or

    Environ("UserName")





Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured