Userform Password

Mkammari

Board Regular
Joined
Nov 23, 2005
Messages
65
I have a main menu userform(VBA) that has security considerations(minor security). I have a command button for Administrative, that will unhide sheets and allow the person to make certain changes to a database. Does anyone know of a simple code to ask for a password to all the user access to the worksheet...and to disallow if the password is incorrect.
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
This may be a start:

<font face=tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
    <SPAN style="color:#00007F">Dim</SPAN> pw <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> ans <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    
        pw = "yada"
        ans = InputBox("Please enter the Password", "*****")
        
        <SPAN style="color:#00007F">If</SPAN> ans = pw <SPAN style="color:#00007F">Then</SPAN>
            Sheets("Sheet1").Visible = <SPAN style="color:#00007F">True</SPAN>
        <SPAN style="color:#00007F">Else</SPAN>
            Sheets("Sheet1").Visible = <SPAN style="color:#00007F">False</SPAN>
            MsgBox "Incorrect Password", vbInformation + vbOKOnly, "Buh Bye"
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
        
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty
 

Mkammari

Board Regular
Joined
Nov 23, 2005
Messages
65
Hiding the password

Is there anyway to make the password hidden? For example, have it show up as *****...rather than a visible word?
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536

ADVERTISEMENT

You can create a Password Input UserForm and set its Password Character property to "*****".

It only takes a ferw minutes more and it's still seamless to the user.

Smitty
 

Sprucy

Board Regular
Joined
Oct 31, 2005
Messages
92
Question!

Hey guys,

Can I set multiple passwords?
I've posted a similar question and no one could help.

I would like about 60 usernames with 60 passwords.
Once I've got that, I will need to code something like..
For all changes made on sheet, add username into Z

So, if Tom Waits (psswrd 10) log's in,
and makes changes to A1, A5, B6, C7,
Cells Z1, Z5, Z6 & Z7 would show Tom Waits

Does this make sense?
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Sure,

It's easiest on a hidden sheet with a column for user name and another one for password.

If you PM me your e-mail address I'll send you a workbook that shows how to do it.

Smitty
 

Watch MrExcel Video

Forum statistics

Threads
1,118,169
Messages
5,570,656
Members
412,335
Latest member
cinciri99
Top