VBA Code


Sheets("Sheet1").Protect 
ActiveSheet.Unprotect

Sheets("Sheet1").Protect Password:="myPassword", _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=True, _
    AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, _
    AllowSorting:=False, _
    AllowFiltering:=False, _
    AllowUsingPivotTables:=False

If (Sheets("Sheet1").ProtectContents) Then
   Call MsgBox ("This worksheet is protected")
End If

If (Sheets("Sheet1").ProtectDrawingObjects) Then
If (Sheets("Sheet1").ProtectScenarios) Then

Sheets("Sheet1").Range("A1").Locked = True
Sheets("Sheet1").ChartObjects("Chart 1").Locked = True
Sheets("Sheet1").Shapes("Rectangle 1").Locked = True
Sheets("Sheet1").Scenarios("ScenarioName").Locked = True

Sheets("Sheet1").EnableSelection = xlNoRestrictions
Sheets("Sheet1").EnableSelection = xlUnlockedCells


© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrev