You need to insert this in the Workbook's code. To do this, open the VBA editor window (ALT+F11). In the Project Explorer window (usually the top left window), find your workbook and double click on the object titled "ThisWorkbook". This will open a new window on the right. Copy this code into that window and change your start and end times to the appropriate times.
Private Sub Workbook_BeforeClose(Cancel As Boolean) If Time >= TimeValue("08:30") And Time <= TimeValue("17:00") Then Else Me.Saved = True End If End Sub Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) If Time >= TimeValue("08:30") And Time <= TimeValue("17:00") Then Else Cancel = True End If End Sub
Copyright ©
2001 by Barrie R. Davidson
Added November, 2001