I have a macro that is set to save and close the a workbook after a set time. I also have a macro that protects all sheets within the workbook. My problem is when I try and call ProtectAllWorksheets macro I get an error sub or function not defined. I know the macro works. I have tried moving the ProtectAllWorksheets to the module and that made the macro work. However, it also locked all cells in every open workbook.
Code below is in a Module:
Code below is in ThisWorkBook
Code below is in a Module:
VBA Code:
Public NoActivity As Date
Sub StopClock()
On Error Resume Next
Application.OnTime NoActivity, "ShutDown", , False
End Sub
Sub StartClock()
NoActivity = now + TimeValue("00:02:00")
Application.OnTime NoActivity, "ShutDown"
End Sub
Sub ADD()
AddNew.show
End Sub
Sub ShutDown()
Call ProtectAllWorksheets
Application.DisplayAlerts = False
With ThisWorkbook
'.Save
'.Close
End With
End Sub
Code below is in ThisWorkBook
Code:
Private Sub Workbook_Open()
MsgBox ("The data entry log is set to save and close in 2 minutues of inactivity")
Call StartClock
End Sub
Private Sub Workbook_SheetCalculate(ByVal sh As Object)
Call StopClock
Call StartClock
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopClock
Call ProtectAllWorksheets
ActiveWorkbook.Save
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)
Call StopClock
Call StartClock
End Sub
Sub ProtectAllWorksheets()
Dim Ws As Worksheet
For Each Ws In Worksheets
Ws.Unprotect "clcRox"
Ws.Cells.Locked = True
Ws.protect "clcRox", AllowFiltering = True
Next Ws
End Sub