LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBa, Password protected sheet fails to get unprotected with the same password

Hi all,

I've been looking into the newsgroups but couldn't find a similar
post.
Here's the problem. I've got two routines. One to protect a bunch of
sheets and one to unprotect these with the same password. The password
is hardcoded and doesn't change (see code hereunder). My OS = W2K,
office 2K (both UK-versions).

The answer the error object returns: "The password you supplied is not
correct. Verify that the CAPS LOCK key is off and be sure to use the
correct capitalization."

_________

Sub Unprotect_Projects()

Dim intLoop As Integer
Dim strSheet As String
Dim objWorksheets As Worksheet

On Error GoTo HeHe

strSheet = ActiveSheet.Name

For intLoop = 1 To 500

Set objWorksheets = Sheets(intLoop)
If Val(objWorksheets.Name) 0 Then
objWorksheets.Select
If ActiveSheet.ProtectContents = True Then
ActiveCell.Select
' Call ActiveSheet.Unprotect("hans")
ActiveSheet.Unprotect password:="hans"
Else
Debug.Print "Werkblad " & objWorksheets.Name
End If
Else
Debug.Print "Naam werkblad " & intLoop & " niet numeriek "
End If
Next

HeHe:
'Klaar
Debug.Print Error(Err.Number)
Select Case Err.Number
Case 9
Debug.Print "Voorbij het laatste werkblad."
Case otherwise
Debug.Print "Onbekende fout: " & Err.Number
End Select

Debug.Print MsgBox("Laatste rekenblad is: [" & objWorksheets.Name
& "]")
Worksheets(strSheet).Activate


End Sub


Sub Protect_Projects()

Dim intLoop As Integer
Dim strSheet As String

On Error GoTo HeHe

strSheet = ActiveSheet.Name

For intLoop = 1 To 500

Set objWorksheets = Sheets(intLoop)
If Val(objWorksheets.Name) 0 Then
objWorksheets.Select
If ActiveSheet.ProtectContents = False Then
ActiveSheet.Protect password = "hans",
DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End If
Next


HeHe:
'Klaar

Worksheets(strSheet).Activate

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrive password protected worksheet but forgot password? Laurie Excel Worksheet Functions 1 November 19th 09 09:42 PM
no password for protected sheet TJaques Excel Worksheet Functions 3 July 27th 06 05:51 PM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM
password protected Sheet thrava Excel Discussion (Misc queries) 4 December 29th 04 07:54 PM


All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"