Hi,
I have the following code saved under the "This Workbook" object
I also have a macro button within the spreadsheet which runs the following code to allow users to manually edit a locked sheet
My problem is, when users select the manually edit macro button, make their changes, then save/exit the sheet, the codes in "This workbook" dont work. So when the next user opens the sheet, it remains unprotected.
Can someone help me solve this issue.
I have the following code saved under the "This Workbook" object
Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim wsRegister As Worksheet
Set wsRegister = ThisWorkbook.Sheets(Register)
wsRegister.Unprotect Password:="BWI2018"
If wsRegister.FilterMode = True Then wsRegister.ShowAllData
wsRegister.Protect Password:="BWI2018", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True
Application.GoTo Reference:=Range("a1"), Scroll:=True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wsRegister As Worksheet
Set wsRegister = ThisWorkbook.Sheets(Register)
wsRegister.Unprotect Password:="BWI2018"
If wsRegister.FilterMode = True Then wsRegister.ShowAllData
wsRegister.Protect Password:="BWI2018", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True
Application.GoTo Reference:=Range("a1"), Scroll:=True
End Sub
Private Sub Workbook_Open()
Dim wsRegister As Worksheet
Set wsRegister = ThisWorkbook.Sheets(Register)
wsRegister.Protect Password:="BWI2018"
Application.GoTo Reference:=Range("a1"), Scroll:=True
End Sub
I also have a macro button within the spreadsheet which runs the following code to allow users to manually edit a locked sheet
Code:
Sub Manual_Entry_or_Edit()
Dim Ans As String
Ans = MsgBox("Editting the register requires administrator rights. Do you wish to proceed?", vbYesNo, "Confirm")
If Ans = vbYes Then
On Error GoTo ErrHandl
ActiveSheet.Unprotect
End If
Exit Sub
ErrHandl:
MsgBox Err.Description
End Sub
My problem is, when users select the manually edit macro button, make their changes, then save/exit the sheet, the codes in "This workbook" dont work. So when the next user opens the sheet, it remains unprotected.
Can someone help me solve this issue.