I have been asked to setup a multi-user spreadsheet to record hours worked. Each user can only access their specific sheet and use a password to make changes. I then need the worksheet to automatically lock on closure.
I have enabled Macros and added the following
Sub ProtectALLShts()
Dim Pwd
Pwd = "1230" '<<< change password !!!
For Each ws In Sheets
If ws.ProtectContents = False Then
ws.Protect Password:=Pwd
End If
Next
ActiveWorkbook.Save
End Sub
I have then added
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Run "ProtectALLShts"
End Sub
It worked great for one test user. I then duplicated the first section with a seperate password and then got an error message when trying to close the spreadsheet. Run-time error 1004 Cannot run the macro ProtectAllShts. The macro may not be available in this workbook or all macros may be disabled.
I have checked Developer Macro Security for Macro Settings and enabled Trust access to the VBA project object module.
Any ideas or different way to setup a spreadsheet to record work hours appreciated.