picklefactory
Well-known Member
- Joined
- Jan 28, 2005
- Messages
- 508
- Office Version
- 365
- Platform
- Windows
Hi folks. I have a WB that can be opened read only (Password protected to edit) on numerous terminals around our place. I have the following code I use to close it down after 30 mins of inactivity, but it still seems to keep a connection after closing, as when it shuts down via the macro, if I try and open it from another terminal it won't let me in as it shows the previous user as still using it, even though they are not. If they then open any other Excel WB, they then get the password window for this WB, even though it is shut, once they press cancel on that it allows access from elsewhere.
Have I missed something in my code please and maybe not closing it fully?
This section in 'This Workbook'
And this section in a module
Have I missed something in my code please and maybe not closing it fully?
This section in 'This Workbook'
VBA Code:
Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("00:30: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
With ThisWorkbook
.Saved = True
.Close
End With
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
And this section in a module
VBA Code:
Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("00:30: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
With ThisWorkbook
.Saved = True
.Close
End With
End Sub