G
Guest
Greetings and TIA for your time
I am using the code below to protect selected worksheets so that the user
can only select unlocked cells and can enter comments (in unlocked cells)
Running the code below has the desired effect. However, when I save the
file, close and re-open, the protection is still in place but the user can
now also select locked cells. How do I prevent the user selecting locked
cells after save, close and re-open?
Sub ProtectSelectedSheets()
Dim wks As Worksheet
Dim myarray()
ReDim myarray(1 To ActiveWindow.SelectedSheets.Count)
counter = 0
For Each wks In ActiveWindow.SelectedSheets
counter = counter + 1
myarray(counter) = wks.Name
Next
For i = 1 To counter
With Worksheets(myarray(i))
.EnableSelection = xlUnlockedCells
.Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True
End With
Next
End Sub
I am using the code below to protect selected worksheets so that the user
can only select unlocked cells and can enter comments (in unlocked cells)
Running the code below has the desired effect. However, when I save the
file, close and re-open, the protection is still in place but the user can
now also select locked cells. How do I prevent the user selecting locked
cells after save, close and re-open?
Sub ProtectSelectedSheets()
Dim wks As Worksheet
Dim myarray()
ReDim myarray(1 To ActiveWindow.SelectedSheets.Count)
counter = 0
For Each wks In ActiveWindow.SelectedSheets
counter = counter + 1
myarray(counter) = wks.Name
Next
For i = 1 To counter
With Worksheets(myarray(i))
.EnableSelection = xlUnlockedCells
.Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True
End With
Next
End Sub