Long standing VBA has stopped functioning

picklefactory

Well-known Member
Joined
Jan 28, 2005
Messages
525
Office Version
  1. 365
Platform
  1. 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

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
 
Just checked this code on my machine running Excel 365 and it works fine. Do you have any other code in the workbook that disables error handling?
 
Upvote 0
Which version and build are you on? If it's just stopped working with no code or structure changes, I'd suspect a bug in the version you're on.
 
Upvote 0
Does seem strange, have you tried adding DoEvents before the Application.Quit line?

Just in case Excel is not update the UI before quitting.
 
Upvote 0
Where is the workbook saved, and is the Edit Log getting updated correctly? If so, I'd move the code to activate the sheet before the lines that update the edit log sheet.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top