Share via

Stop auto-close timer

Anonymous
2014-11-20T16:24:54+00:00

I use the following for a workbook on a shared drive. It works well.... People log events etc on the workbook and I installed this to auto-close the workbook after 2 mins of inactivity just in case they forget to close. 

However, occasionally I need to be able to temporarily stop this from triggering without having to delete it (when I am in it reviewing the log). 

Any ideas?

Private Sub Worksheet_Change(ByVal Target As Range)

    If EndTime Then

        Application.OnTime _

        EarliestTime:=EndTime, _

        Procedure:="CloseWB", _

        Schedule:=False

        EndTime = Empty

    End If

    EndTime = Now + TimeValue("00:02:00")

    RunTime

End Sub

Public EndTime

Sub RunTime()

    Application.OnTime _

    EarliestTime:=EndTime, _

    Procedure:="CloseWB", _

    Schedule:=True

End Sub

Sub CloseWB()

    Application.DisplayAlerts = False

    With ThisWorkbook

        .Saved = False

        .Close

    End With

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2014-11-23T13:45:14+00:00

    Unfortunately, that didnt work for me...

    Strange, that works for everyone else. If you like you can add this 2 macros:

    Sub EventsOff()

      Application.EnableEvents = False

    End Sub

    Sub EventsOn()

      Application.EnableEvents = True

    End Sub

    and so switch the events off, resp. on afterwards, but the same happens when you click the Design Mode button.

    BTW, a technical note: When the events are off, the Worksheet_Change event routine isn't executed anymore, until you switch the events on.

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-11-21T15:45:57+00:00

    Unfortunately, that didnt work for me... 

    I did just find a clip somewhere that mentioned...

    Wild shot... but trying
    

    Could I implement something like this... that maybe says, if the value in a cell is true, disable the worksheet change event. 

    Application.EnableEvents = False
        Sheet1.Range("A1").Value = "new"
    Application.EnableEvents = True
    

    I dont know how to implement this in the worksheet change, but maybe someone does?

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2014-11-21T11:12:08+00:00

    Click the "Design Mode" button in the Developer tab. This interrupts all macros.

    Andreas.

    Was this answer helpful?

    0 comments No comments