Shared Workbook - Auto close when idle too long, still showing as open?

Alan_P

Well-known Member
Joined
Jul 8, 2014
Messages
596
Hi All,

I'm wondering if someone can help, I have a shared workbook that I've added the below code to so that it automatically saves and closes if someone has it open for 30 minutes and hasn't used it (it was constantly annoying people leaving it open all the time!!) :banghead:

It works perfectly except for one thing... When I go to un-share the workbook to do updates it still says several people have it open even tho I know this isn't the case.

Does anyone know what causes this and how to solve it?

Much appreciated,
Cheers,
Alan.

In ThisWorkbook:

Code:
Private Sub Workbook_Open()
a = MsgBox("Please close this file when not being used!" & vbNewLine & "File will be closed after 30 minutes of inactivity", vbCritical, "********** WARNING **********")
nElapsed = TimeSerial(0, 30, 0) '30 minutes
nTime = Now + nElapsed
Application.OnTime nTime, "Countdown"
End Sub

-------------------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime EarliestTime:=nTime, Procedure:="Countdown", Schedule:=False
End Sub

-------------------------------------------------------------
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnTime nTime, "Countdown", , False
nTime = Now + nElapsed
Application.OnTime nTime, "Countdown"
End Sub

-------------------------------------------------------------
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.OnTime nTime, "Countdown", , False
nTime = Now + nElapsed
Application.OnTime nTime, "Countdown"
End Sub

-------------------------------------------------------------
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.OnTime nTime, "Countdown", , False
nTime = Now + nElapsed
Application.OnTime nTime, "Countdown"
End Sub

In a standard Module:

Code:
Option Explicit
Public nElapsed As Double
Public nTime As Double

-------------------------------------------------------------
Public Sub Countdown()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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