Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Workbook setup

Status
Not open for further replies.

woz2002

IS-IT--Management
Feb 27, 2003
5
0
0
GB
Hi all rarely post on here less im stuck.
I cant get my head round the following problem:

I have a workbook with multiple worksheets. I need the user to only se their respective work sheet & hide all of the others. The only way i know of to do this is using an input box & based on the results of that input...set the workbook accordingly. The problem is How do I set it so that a value must be entered & that if the value = x then do x, if z then do z ??

Heres what Im toying with at current.
___________________________________________
Private Sub Workbook_Open()
Login
End Sub
___________________________________________
Private Sub Login()
Dim Password As String
Do Until Password <> ""
Password = InputBox("Enter your Password: ", "Secure Login")
If Password = "123" Then
Sheet1.Visible = False
Sheet3.Visible = False
Sheet2.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
End If

Loop
ActiveWorkbook.Protect Structure:=True, Windows:=False
End Sub
___________________________________________

....any help would be gratefully appreciated :)
 
Doh....kicks self in rear....

..Select Case!
 
Just add a blank worksheet (called Login) and a seperate module for your validation code and put your validation routine in:
Code:
Public Sub Qvalidate()
Sheet1.Visible = xlSheetHidden
Sheet2.Visible = xlSheetHidden
Sheet3.Visible = xlSheetHidden

myPass = InputBox("Enter Password")
Select Case myPass
Case "abc"
Sheet2.Visible = xlSheetVisible
Sheet2.Activate
Case "def"
Sheet1.Visible = xlSheetVisible
Sheet1.Activate
Case Else
MsgBox "Error in password"
ActiveWorkbook.Close
End Select
End Sub

The call Qvalidate in your WorkBook_Open Event (in ThisWorkBook module) and in the Worksheet_Activate Event for your Login Worksheet

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top