NT username...

Ian Mac

MrExcel MVP
Joined
Feb 20, 2002
Messages
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.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Don't know, but you could write a macro to protect all the sheets and unprotect them all with one single command.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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??)
 
Upvote 0
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 :biggrin:)

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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,136
Members
448,551
Latest member
Sienna de Souza

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top