Results 1 to 3 of 3

Thread: Password Access for a sheet

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    5

    Password Access for a sheet

    I am new to writing VBA and need to restrict access to a sheet in a workbook. I have macro that assigns a password to the sheet, but it seems that the password isnt defined as anything entered will unlock the password. Can someone please look at my code and identify where I am missing assigning the password a value?
    Code:
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Dim strPass As String
    correct_pass_given = 0
    Dim lCount, number_of_tries_allowed As Long
    Set hide_sheet = Sheet11 ' Give the name of the sheet to hide (This is not the Sheet Tab name but the one that shows outside the bracket.)
    number_of_tries_allowed = 3 'this is to restrict the number of tries at one go
    'MsgBox correct_pass_given
    
    If ActiveSheet.Name <> "ContractorInformation" Or correct_pass_given = 1 Then
    Else
     hide_sheet.Columns.Hidden = True
     'Allow 3 attempts at password
     For lCount = 1 To number_of_tries_allowed
      strPass = InputBox(Prompt:="Password Please", Title:="PASSWORD REQUIRED")
       If strPass = vbNullString Then 'Cancelled
          MsgBox "Password incorrect", vbCritical, "Message"
       Else: correct_pass_given = 0 'Correct Password
          Exit For
       End If
     Next lCount
     If lCount = number_of_tries_allowed + 1 Then 'They use up their 3 attempts
     Exit Sub
    Else 'Allow viewing
      hide_sheet.Columns.Hidden = False
      End If
      End If
     End Sub
    Last edited by si_the_geek; Sep 28th, 2010 at 09:14 AM. Reason: added Code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width