workbook Protection Toggle Macro

J

Just Learning

Does anyone have a macro for toggling workbook protection?

E.g., run the macro and it unprotects the workbook if it's in a protected
state and vice versa.

Thanks for any help given!
 
D

Don Guillett

try

Sub protectunprotecttoggle()
If ActiveWorkbook.ProtectStructure = True Then
ActiveWorkbook.Unprotect Password = "d"
Else
ActiveWorkbook.Protect structure:=True, Windows:=False, Password:="d"
End If
End Sub
 
J

Just Learning

Thanks! It works great!

Don Guillett said:
try

Sub protectunprotecttoggle()
If ActiveWorkbook.ProtectStructure = True Then
ActiveWorkbook.Unprotect Password = "d"
Else
ActiveWorkbook.Protect structure:=True, Windows:=False, Password:="d"
End If
End Sub
 
Top