+ Reply to Thread
Results 1 to 6 of 6

Get username

Hybrid View

Schwizer Get username 03-07-2007, 12:52 PM
dominicb Good afternoon Schwizer ... 03-07-2007, 01:11 PM
Schwizer Under tools -> options ->... 03-07-2007, 01:30 PM
jetted I use the following code to... 03-07-2007, 01:47 PM
Schwizer Thank you, that also works... 03-07-2007, 01:55 PM
jasoncw Another version of code you... 03-07-2007, 02:10 PM
  1. #1
    Registered User
    Join Date
    01-29-2007
    Posts
    92

    Get username

    I would like the macro to be able to retrieve the username of the person on the computer. I tried

    Application.username but it returns the value "Administrator"

    I'm an administrater on my machine but that is not the username I use. Are there any other similar commands i could try?

    Thank you
    Schwizer

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon Schwizer

    The code you supplied returns the username found under Tools > Options, General function. What do you want returning? If this is the logged on username then try this link :

    http://vbnet.mvps.org/index.html?code/internet/ping.htm

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    01-29-2007
    Posts
    92
    Under tools -> options -> save

    I have under "AutoRecover Save Location"
    C:\Documents and Settings\BSchwizer\Application Data\Microsoft\Excel\

    I am looking for a command that returns "BSchwizer". Or in other words, the text between the "\"s after "Documents and Settings"

    Is this possible?

    Thanks
    Schwizer

  4. #4
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    I use the following code to get the userid

    Sub User()
    Dim objNet
    Set objNet = CreateObject("WScript.NetWork")
    MsgBox objNet.UserName
    End Sub
    Denis

    Please always attach the sample workbook without sensitive information when asking for help

    To add a module
    Press Alt + F11 (this is the Visual Basic Environment)
    Insert Menu, select Module
    Past code there
    Close Visual Basic Environment (X)

  5. #5
    Registered User
    Join Date
    01-29-2007
    Posts
    92
    Thank you, that also works for me. I've also found a way to get the autosave string so i've extracted it from that

    tester = Application.AutoRecover.Path
    Start = InStr(tester, "Settings") + 9
    endd = InStr(tester, "\Application")
    user = Mid(tester, Start, endd - Start)
    I'm making some assumptions here but its not a critical part of the macro.

    Schwizer

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Another version of code you could use is:

    UserID = Environ$("username")

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1