Greetings all,
Something very strange happening that I am hoping someone can shed light on ...
I have a private sub in the worksheet module. At the start of the sub I test to see if the worksheet is protected or unprotected. If protected, I set a boolean variable to TRUE. I then unprotect the sheet to perform some actions and then at the end of the sub I simple exit if the the worksheet was initially unprotected or I protect the sheet if it was originally protected.
When I reprotect the sheet, I use the options to allow the user to use filtering and to sort a table. However, when the event code runs upon sheet activation, the resulting level of protection is only allow selection of the unlocked cells. The user is not allowed to use the filter / sort functions on the table.
The strange part is that if I place the sheet protection statement outside of the If-Then-Else statement, then the appropriate level of protection is applied and the user can then perform filters and sorts.
Anyone have any idea what might be going on? Any workaround?
Thanks,
Steve
Something very strange happening that I am hoping someone can shed light on ...
I have a private sub in the worksheet module. At the start of the sub I test to see if the worksheet is protected or unprotected. If protected, I set a boolean variable to TRUE. I then unprotect the sheet to perform some actions and then at the end of the sub I simple exit if the the worksheet was initially unprotected or I protect the sheet if it was originally protected.
VBA Code:
Private Sub Worksheet_Activate()
Dim reprotect As Boolean
Dim c As Range
Dim i As Integer
‘ Check is the sheet is protected. If it is, set reprotect variable to TRUE
If Sheet1.ProtectContents = True Then
Sheet1.Unprotect
reprotect = True
Else
reprotect = False
End If
….
Do stuff here while sheet is unprotected
….
‘ Reprotect the sheet if originally protected
If reprotect = True Then
Sheet1.Protect DrawingObjects:=True, Contents:=True, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
Sheet1.EnableSelection = xlUnlockedCells
Else
End If
End Sub
When I reprotect the sheet, I use the options to allow the user to use filtering and to sort a table. However, when the event code runs upon sheet activation, the resulting level of protection is only allow selection of the unlocked cells. The user is not allowed to use the filter / sort functions on the table.
The strange part is that if I place the sheet protection statement outside of the If-Then-Else statement, then the appropriate level of protection is applied and the user can then perform filters and sorts.
Anyone have any idea what might be going on? Any workaround?
Thanks,
Steve