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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can no longer protect worksheets

Status
Not open for further replies.

tech84

Technical User
May 18, 2000
126
US
I opened a spreadsheet from the State of Utah dealing with air emissions, and there was a macro/script to disallow unprotecting the sheet. The trouble is that now I cannot protect or unprotect any spreadsheets, period. I've reinstalled Office to no avail. My Office version is 2003. I've looked at the code, but I don't see a way to reverse the changes. Does anyone know where this type of security setting might be found (registry, etc.) and how I can change it back? Here's the code that causes the problem:


Sub ProtectSheets()
'
' This macro protects all of the sheets in the active workbook, as well
' as the workbook itself. It protects everything with the correct
' password using the variable "Password". "Password" is a public
' string variable that is defined in Module1. If the user does not have
' permission to enter the password ("blnPermission = False") then this
' macro is terminated ("Exit Sub"). "blnPermission" is a public variable
' that also is defined in Module1.
'
If blnPermission = False Then
Exit Sub
End If
'
' "Sheets" is an array that is internal to Excel. It holds all of the
' worksheets and all of their related properties.
'
' The "If" statement inbeded within the following "For" loop ensures that
' the printout sheets don't get protected. This is so that the user is
' allowed to manipulate them as he/she pleases.
'
For Each Wks In Sheets
If Len(Wks.Name) > 4 And InStr(1, Wks.Name, "F") <> 1 _
And Wks.Name <> "Tanks" And Wks.Name <> "Detailed Summary" Then
'Debug.Print Wks.Name
Wks.Protect Password:=PWord ', DrawingObjects:=True, _
Contents:=True, Scenarios:=True

End If
Next Wks
If ExistSheet("Tanks") Then
Sheets("Tanks").Protect ("Tanks")
End If
ThisWorkbook.Protect Password:=PWord ', Structure:=True, Windows:=True
'
' The following code changes the caption on the command button found on
' the "INPUT" sheet to "Unprotect".
'
Sheets("INPUT").cmdProtection.Caption = "Unprotect"

End Sub

Thankd for any help you can provide!

Mike
[morning]
 
this code should not cause that effect

It also seems to be missing a chunk of code....where is blnPermission set ? for instance
 
Can you run any saved macro? Try to debug the above code.
What is the macro secutity level (Tools>Macro>Security or Tools>Options>Security tab and macro security button)? To enable saved macros, it should be set to medium, the user is prompted to enable/disable macro. High security (default after installation) disables macros without warning.

combo
 
I've got the same problem with (surprise!) a workbook from the State of Utah dealing with air emmissions. Tech84, did you ever find a solution?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top