Results 1 to 9 of 9

Thread: [RESOLVED] Get user name

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Resolved [RESOLVED] Get user name

    I am creating a userform that will be used by a variety of users to input data into the one excel workbook. I would like the code to get the user name out of excel and onto the worksheet.

    Thank you in advance.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Get user name

    "Out of excel" What does that mean?

    It is easy as pie to get the windows login name, but I've no clue what you mean by 'out of excel'

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Re: Get user name

    If, for instance, I look at my Excel Options (the one you access through the Office button in Excel 2007), or if I look at the options that are found at the bottom of the tools drop down menu in earlier versions of Excel the copy of Excel is registered to a particular user, who can then personalise it. This is the user name I want to "get out of" Excel. (This does, of course, assume that users are logged in to the system under their own user ID. This is a reasonably safe assumption. In the event that a user is logged in under someone else's ID and is actually working the ID owner would know about it.)

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Get user name

    I've always used the windows logon name. In my shop, the user name is actually irrelevant. It is the same for 4,000 + people and that is the name of the company.

    At any rate, I found this through Google. I think it is what you are looking for (it does return the name of the company I work at when I run it)
    Code:
    Private Sub CommandButton1_Click()
    MsgBox Application.UserName
    End Sub

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Get user name

    There is also the Environ Function in VBA.

    vb Code:
    1. Function UserNameWindows() As String
    2.     UserName = Environ("USERNAME")
    3. End Function
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Get user name

    That returns the windows login, not the name registered in Excel.

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Get user name

    Ah! yes, you are right Hack...

    In my company, the login name is reflected in the applicaton.username for all users in Excel...

    Edit: I just checked 3 users who are on a network, and it shows their domain login names when I use Application.Username. I guess, the IT guys have made it user-specific in my company
    Last edited by Siddharth Rout; Jun 26th, 2009 at 09:29 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Get user name

    Here, your windows login is your company ID badge number so I'm C123456

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Re: Get user name

    Thanks everyone! Application.UserName works a treat!

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