Autoclose Macro Error

DanA1509

New Member
Joined
Oct 17, 2013
Messages
33
Hi All,

Im having an issue with a timer macro developed from a forum page here
HTML:
http://www.mrexcel.com/archive/VBA/7422a.html

I have also looked at
HTML:
http://www.mrexcel.com/forum/excel-questions/18477-automatically-close-workbook-after-x-time.html
and
HTML:
http://www.mrexcel.com/forum/excel-questions/257877-close-unused-workbook-automaticcly-after-specific-time.html
, and though both are useful, honestly I'm utterly confused at what I see and really am not sure what I need to produce and where.

Currently Im using the macro from the first link and it is causing the workbook to essentially not load, at the point of writing this it has been 5 minutes and it is still stuck on the excel loading screen.

All I'm in need of is a macro that will autoclose the workbook after five minutes if there has been no editting of the workbook. One thing I should add is I also have a macro and form that generate and populate a new line. I don't know if it will affect anything but by clicking the macro button that activity should reset the timer.

I hope its understandable with what I've said but any help would be greatly appreciated right now
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
[EDIT As can't update previous]

I now have found a thread that appears to work. Im surrently using:
In ThisWorkbook:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Zerotime
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'ThisWorkbook Module Code!
If ActiveSheet.FilterMode = True Then ActiveSheet.ShowAllData
ActiveWorkbook.Save
End Sub

And in module 1:

Code:
Dim Lasttime As Double
Dim Thistime As Double
Sub auto_open()
Application.OnEntry = "zerotime"
Lasttime = Now
Thistime = Now
CounterTime
End Sub
Sub auto_Close()
Application.StatusBar = False
Application.OnEntry = ""
If Thistime < TimeSerial(0, 5, 0) Then
ThisWorkbook.Close True
End
End If
Application.OnTime Now() + TimeSerial(0, 5, 0), procedure:="countertime", schedule:=False
If ActiveSheet.FilterMode = True Then ActiveSheet.ShowAllData
ActiveWorkbook.Close SaveChanges:=True
End Sub
Sub CounterTime()
Thistime = Now - Lasttime
Application.StatusBar = "Unused for " + Format(Thistime, "hh.mm.ss") + ". Closes in 00.05.00"
If Thistime > TimeSerial(0, 5, 0) Then
If ActiveSheet.FilterMode = True Then ActiveSheet.ShowAllData
ThisWorkbook.Close True
End
End If
Application.OnTime Now() + TimeSerial(0, 0, 1), "countertime"
End Sub
Sub Zerotime()
Lasttime = Now()
End Sub

One thing I want to change with this is to reset the timer when any activity is noticed, a click on a cell, a button or to type in a new value... anyone know how to help?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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