Results 1 to 5 of 5

Thread: Missing Syntex

  1. #1
    3 Star Lounger
    Join Date
    May 2008
    Location
    India
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Need error handler within the code if password supplied to unprotect the sheets is incorrect. The password is given in code to hide the sheets.

    Code:
    Sub unhide()
    	Dim sht As Variant
    	For Each sht In ActiveWorkbook.Sheets
    	sht.Unprotect
    	Next
    	Dim strName As Variant
    	For Each strName In Array("BG-3 (ALL)", "BG-3 (WO ANS & ANTB)", _
    	"COMPONENT", "SSC", "EXHAUST", "RIM", "HRD", "PNG", "ANS", "ANTB")
    	With Worksheets(strName)
    	.Columns("A:AH").Hidden = False
    	.Select
    	.Range("A1").Select
      End With
      Next
      Sheets("Key Ratio ").Select
      Range("A3:A4").Select
    End Sub
    Regards
    Prasad

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    What do you want to happen if the user provides an incorrect password? End execution of the macro, or continue with the next sheet?

  3. #3
    3 Star Lounger
    Join Date
    May 2008
    Location
    India
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='783776' date='09-Jul-2009 15:36']What do you want to happen if the user provides an incorrect password? End execution of the macro, or continue with the next sheet?[/quote]
    need a msg box to appear twice to allow user to provide correct password, failing which it will jump to next sheet. am I clear?
    Regards
    Prasad

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could change the first loop to

    Code:
      For Each sht In ActiveWorkbook.Sheets
    	On Error Resume Next
    	sht.Unprotect
    	If Err Then
    	  MsgBox "Password incorrect. Please try again.", vbExclamation
    	  sht.Unprotect
    	  If Err Then
    		MsgBox "Boo!", vbExclamation
    	  End If
    	End If
    	On Error GoTo 0
      Next sht

  5. #5
    3 Star Lounger
    Join Date
    May 2008
    Location
    India
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='783931' date='10-Jul-2009 09:13']You could change the first loop to

    Code:
      For Each sht In ActiveWorkbook.Sheets
    	On Error Resume Next
    	sht.Unprotect
    	If Err Then
    	  MsgBox "Password incorrect. Please try again.", vbExclamation
    	  sht.Unprotect
    	  If Err Then
    		MsgBox "Boo!", vbExclamation
    	  End If
    	End If
    	On Error GoTo 0
      Next sht
    [/quote]
    Exactly what i was looking for. Thaaaaanks .
    Regards
    Prasad

Posting Permissions

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