View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default UserName Property

In Excel, ToolsOptionsGeneral, there is a name input box there.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"AccessHelp" wrote in message
...
Chip,

Thanks for the code. What is the Options dialog?

"Chip Pearson" wrote:

Application.UserName is completely independent of the Windows logon name.
The UserName is simply what is entered in the Options dialog. You can get
the actual Windows user name with

Dim UName As String
UName = Environ("Username")

For multiple authorized users, use code like

Dim UName As String
UName = LCase(Environ("UserName")) ' for to all lower case
Select Case UName
Case "name one", "name two", "name three" ' use lower case names
' authorized users
Case Else
' unauthorized user
End Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"AccessHelp" wrote in message
...
Good morning,

I have a command button in a workbook to run a macro. However, when a
user
clicks on the button, the macro will check first automatically whether
the
user who clicks on it has an authority to run the macro. If not, the
user
will receive a message "Access denied.".

So I came up with the following code:

If Application.UserName < "John Doe" Then
Msgbox "Access denied."
Else
run the remainder of code......
End If

2 questions:

1. What does the UserName Property check against with? Does it check
against with Windows user name or computer user name? When I did the
code
"Msgbox Application.UserName", I got my first and last names.
2. I will have more than one authorized users, and instead of having
the
code "If Application.UserName < "John Doe" Or If Application.UserName
<
"John Smith" Or ......", can you help me with better coding?

Thanks.