How to unprotect a workbook by macro?

F

FARAZ QURESHI

HELP! HELP! HELP!
I have a workbook with its structure locked. How to unprotect a workbook by
macro?
 
J

JLatham

This code will protect a worksheet from change:

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

if you wish to add password protection to that, then:

ActiveSheet.Protect Password:="password", _
DrawingObjects:=True, _
Contents:=True, Scenarios:=True

To unprotect, it is either
ActiveSheet.Unprotect
when there is no password associated with the protection, or
ActiveSheet.Unprotect Password:="password"
when there is a password given. The passwords have to match.

You can only protect/unprotect a single sheet at a time, but if you wish to
do all sheets in a workbook at once:

Sub ProtectOrUnprotect()
Dim anySheet As Worksheet

For Each anySheet in Worksheets
'... put protect or unprotect code here using anySheet instead of
ActiveSheet
' example of unprotecting:
anySheet.Unprotect password:="FARAZ"
Next
End Sub
 
Top