![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
|
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 |
|
Board Regular
Join Date: Mar 2002
Location: London, UK
Posts: 167
|
Don't know, but you could write a macro to protect all the sheets and unprotect them all with one single command.
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Ireland
Posts: 133
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Helena, MT
Posts: 13,690
|
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 |
|
Board Regular
Join Date: Mar 2002
Location: =ActiveCell.Address
Posts: 478
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
|
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 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
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 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
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 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
|
Quote:
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 |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|