I would suggest doing this with an additional hidden sheet, call it timer_lock. Then have a worksheet_change event in every sheet that sets cell A1 of timer_lock equal to 1.
Then use the ontime method to get a macro to check A1 of timer_lock every 2 minutes. If it is 1, set it to 0. If it is 0, close the workbook.
This would look something like this:
In every sheet object module
Sub worksheet_change(byval target as range)
sheets("timer_lock").range("A1") = 1
End sub
In a standard module:
Sub Timer_lock_macro()
if sheets("timer_lock").range("A1") = 1 then
sheets("timer_lock").range("A1") = 0
else
thisworkbook.close
end if
application.ontime now() + "00:02:00"
End sub
Then in your workbook open module:
sub workbook_open()
for each ws in thisworkbook.sheets
if not ws.name = "front sheet name" then ws.hidden = xlhidden
next
end sub
sub workbook_beforesave()
for each ws in thisworkbook.sheets
if not ws.name = "front sheet name" then ws.hidden = xlveryhidden
next
Out of interest what is the aim of doing this? Implementing this code seems a horrendously bad idea to me.
Bookmarks