picklefactory
Well-known Member
- Joined
- Jan 28, 2005
- Messages
- 525
- Office Version
- 365
- Platform
- Windows
Hi folks
Hoping someone can point me in the right direction please?
I have a spreadsheet I've used for years to track holidays with a tab for each month. I have a Workbook BeforeClose function that has always looked at the current month (NOW) and selected that month tab prior to saving and closing. It's always worked fine until this week. I get no error messages or any other issues with it but the WB now simply ignores that element and closes on whatever tab it was left on. In case the WB was corrupt I've tried copying out all the code (Only one module and the ThisWorkbook functions), saving as an xlsx, re-opening and replacing the code and re-saving as an xlsm, but that made no difference. As this workbook is shared across our network, I also have an OnTime function to automatically close it after 10mins of idleness so that no one can leave it open and lock out other users, that bit is still working fine.
This Workbook code is
and the module is
Hoping someone can point me in the right direction please?
I have a spreadsheet I've used for years to track holidays with a tab for each month. I have a Workbook BeforeClose function that has always looked at the current month (NOW) and selected that month tab prior to saving and closing. It's always worked fine until this week. I get no error messages or any other issues with it but the WB now simply ignores that element and closes on whatever tab it was left on. In case the WB was corrupt I've tried copying out all the code (Only one module and the ThisWorkbook functions), saving as an xlsx, re-opening and replacing the code and re-saving as an xlsm, but that made no difference. As this workbook is shared across our network, I also have an OnTime function to automatically close it after 10mins of idleness so that no one can leave it open and lock out other users, that bit is still working fine.
This Workbook code is
VBA Code:
Private Sub Workbook_Open()
Call SetTimer
End Sub
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Call StopTimer
Call SetTimer
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Call StopTimer
Call SetTimer
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = True
Call EditLog
Sheets(Format(Now(), "mmmm")).Select
Application.Quit
End Sub
and the module is
VBA Code:
Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("00:10:00")
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=False
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
Call EditLog
Application.Quit
End Sub
Function LastAuthor()
LastAuthor = ActiveWorkbook.BuiltinDocumentProperties("Last Author")
End Function
Function LastModified() As Date
LastModified = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function
Sub EditLog()
With Worksheets("EDIT LOG")
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 2).Value = Array(LastAuthor(), LastModified())
End With
Sheets(Format(Now, "mmmm")).Activate
End Sub