Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: NT username...

  1. #1
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Newcastle, UK
    Posts
    1,174
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is there a way to find a persons Username in Excel, the reason I ask is I'd like to run macros ONLY if a certain user is logged in.

    Alright!! I'm trying to be lazy, I have 60 sheet workbook ALL the sheets are protected with a password, I'm getting sick of typing the bleedin thing in ALL the time.
    Same with the VBAproject.

    Any ideas, you'd be helping a very lazy man.
    "Have a good time......all the time"
    Ian Mac

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    167
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Don't know, but you could write a macro to protect all the sheets and unprotect them all with one single command.


  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Ireland
    Posts
    133
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I don't think it would be a good idea to go solely on username in Excel, users could just change their name to somebody else's name.

  4. #4
    MrExcel MVP lenze's Avatar
    Join Date
    Feb 2002
    Location
    Helena, MT
    Posts
    13,690
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Not sure how to return the user name, but maybe you could write an On Open procedure that asks for and sets a global password and then use an On WorkSheet.Activate procedure to check this before activating each sheet.

  5. #5
    Board Regular
    Join Date
    Mar 2002
    Location
    =ActiveCell.Address
    Posts
    478
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following:

    MsgBox "Current user is " & Application.UserName

    This didn't bring up my actual network login id, but rather the Excel user, but would this be good enough?

    (Probably depends on your network I guess??)


  6. #6
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Newcastle, UK
    Posts
    1,174
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Don't know, but you could write a macro to protect all the sheets and unprotect them all with one single command.

    I could but people could use that also if it was in if I stored it in This Workbook and I use computers all around the building so Personal Macro Workbook wouldn't work.

    I don't think it would be a good idea to go solely on username in Excel, users could just change their name to somebody else's name.
    Only the adinistrators know my NT login password (and me of course )

    Not sure how to return the user name, but maybe you could write an On Open procedure that asks for and sets a global password and then use an On WorkSheet.Activate procedure to check this before activating each sheet.


    will look into this, but I'd still like the NT login thingy, it'd help with some other things also, like last NT user (not Excel user) in book.

    Try the following:

    MsgBox "Current user is " & Application.UserName

    This didn't bring up my actual network login id, but rather the Excel user, but would this be good enough?

    (Probably depends on your network I guess??)


    it returned McConnell but my NT is MacConnelli, again the NT would be better nearly all our systems Microsoft or not have the surname&initial format, I'd like to use the feature for event logs also (suddenly thought of more realistic uses for this)

    OOPS! thanks for the input.


    _________________
    Share the wealth!!
    Ian Mac

    [ This Message was edited by: Ian Mac on 2002-04-05 07:11 ]

  7. #7
    Board Regular
    Join Date
    Feb 2002
    Location
    Guderup, Denmark
    Posts
    288
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi
    Copy this into a mudule and now use the function getusername(). It takes your NT login name


    Option Explicit
    ' This is used by GetUserName() to find the current user's
    ' name from the API
    Declare Function Get_User_Name Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long


    Function GetUserName() As String
    Dim lpBuff As String * 25

    Get_User_Name lpBuff, 25
    GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
    End Function

    regards Tommy

  8. #8
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    http://support.microsoft.com/default...;EN-US;q148835

    Or:

    Just create your own login script...?

    [ This Message was edited by: TsTom on 2002-04-05 07:40 ]

  9. #9
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Newcastle, UK
    Posts
    1,174
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-04-05 07:38, TsTom wrote:
    http://support.microsoft.com/default...;EN-US;q148835

    Or:

    Just create your own login script...?

    [ This Message was edited by: TsTom on 2002-04-05 07:40 ]
    Tommy Bak, Thanks, that was the fella.

    TsTom most helpfull website cheers, Just create your own login script...? this didn't even touch the top of my head as it went over it
    "Have a good time......all the time"
    Ian Mac

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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