PDA

View Full Version : Solved: How to create a macro to unprotect the sheet?



Esmatullah
01-04-2013, 11:24 PM
Hi dear friends!|
I need a macro that can unprotect the sheet. I mean that when i want to unprotect my sheet without going to Format Ribbon and pressing the unprotect just press the button assigned the macro i want.

jignesh142
01-05-2013, 01:53 AM
ActiveSheet.Unprotect

Paul_Hossler
01-05-2013, 08:37 AM
Option Explicit
Const sPassword As String = "passwordgoeshere"
Sub ToggleProtection()

With ActiveSheet

'if already protected, then unprotect
If .ProtectContents Then
Call .Unprotect(sPassword)
MsgBox .Name & " is unprotected"

Else
.Protect _
Password:=sPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True, _
UserInterfaceOnly:=False, _
AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows:=True, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=True, AllowDeletingRows:=True, _
AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=False
.EnableSelection = xlNoRestrictions
MsgBox .Name & " is protected"
End If
End With
End Sub


Paul