In order for this solution to work, you really should password protect your VB Project. Create a list of user names, passwords, and access to sheets like this:
zzzzzz.xls |
---|
|
---|
| A | B | C | D | E |
---|
1 | UserName | Password | Sheet1 | Sheet2 | Sheet3 |
---|
2 | Billy | Dumb-butt | x | | x |
---|
3 | Tom | Moldy | x | x | |
---|
4 | Juan | Stinky | x | x | x |
---|
|
---|
Make this sheet xlSheetVeryHidden for it's Visible property. Create a worksheet called WELCOME SCREEN that will basically be a background or even just an all black page. Then try this code out:<font face=Courier New><SPAN style="color:darkblue">Private</SPAN><SPAN style="color:darkblue">Sub</SPAN> Workbook_Open()<SPAN style="color:darkblue">Dim</SPAN> Sh<SPAN style="color:darkblue">As</SPAN> Worksheet<SPAN style="color:darkblue">Dim</SPAN> UserName<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">String</SPAN><SPAN style="color:darkblue">Dim</SPAN> Password<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">String</SPAN><SPAN style="color:darkblue">Dim</SPAN> ThisCell<SPAN style="color:darkblue">As</SPAN> Range<SPAN style="color:darkblue">Dim</SPAN> c<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">For</SPAN><SPAN style="color:darkblue">Each</SPAN> Sh<SPAN style="color:darkblue">In</SPAN> ThisWorkbook.Worksheets
<SPAN style="color:darkblue">If</SPAN> Sh.Name<> "WELCOME SCREEN"<SPAN style="color:darkblue">Then</SPAN>
Sh.Visible = xlSheetVeryHidden
<SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Next</SPAN> Sh
UserName = InputBox("Please enter your user name.")
Password = InputBox("Please enter password.")
<SPAN style="color:darkblue">For</SPAN><SPAN style="color:darkblue">Each</SPAN> ThisCell<SPAN style="color:darkblue">In</SPAN> Sheets("User List").Range("A2:A" & Sheets("User List").Range("A65536").End(xlUp).Row)
<SPAN style="color:darkblue">If</SPAN> UCase(ThisCell.Value) = UCase(UserName) And UCase(ThisCell.Offset(, 1).Value) = UCase(Password)<SPAN style="color:darkblue">Then</SPAN>
MsgBox "Access Granted"
<SPAN style="color:darkblue">For</SPAN> c = 2<SPAN style="color:darkblue">To</SPAN> 4
<SPAN style="color:green">'This is the number of sheets from C1 to E1</SPAN>
<SPAN style="color:darkblue">If</SPAN> ThisCell.Offset(, c).Value<> ""<SPAN style="color:darkblue">Then</SPAN>
Sheets(Sheets("User List").Cells(1, c + 1).Value).Visible = xlSheetVisible
<SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Next</SPAN> c
<SPAN style="color:darkblue">Exit</SPAN><SPAN style="color:darkblue">Sub</SPAN>
<SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Next</SPAN> ThisCell
MsgBox "Access Denied"
ThisWorkbook.<SPAN style="color:darkblue">Close</SPAN><SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">Sub</SPAN></FONT>