Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Kill App macro is restarting app
I use this to Save and close the workbook when the user is idle for 10 minutes:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim TimeOut As Date TimeOut = Now() + TimeValue("00:10:00") Application.OnTime TimeOut, "KillApp" End Sub Sub KillApp() ThisWorkbook.Save ThisWorkbook.Close End Sub But as soon as the workbook finishes saving and closing, it opens right back up again??? Can anyone help? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Kill App macro is restarting app
Where are you testing to see if the user is idle? It looks like every time
there is a SelectionChange event on this worksheet, you are scheduling KillApp to occur 10 minutes later. Try this alternate code: In A VBA code module in the same workbook, paste this code: Global StartTime As Single Global Const TimeLimitInMinutes = 10 'idle time threshold Global Const TimeCheckDelay = "00:01:00" 'how often to check Sub CheckTime() Dim NewTime As Single 'Get the time (seconds past midnight) now. NewTime = Timer 'If StartTime was yesterday, add 86400 seconds to NewTime. If NewTime < StartTime Then NewTime = NewTime + 86400 End If 'If TimeLimitInMinutes has expired since StartTime was last 'updated, close the workbook without saving changes. If (NewTime - StartTime) (TimeLimitInMinutes * 60) Then ThisWorkbook.Save ThisWorkbook.Close SaveChanges:=False Else 'Otherwise, schedule a call to CheckTime in the future to check 'again later. Application.OnTime (Now + TimeValue(TimeCheckDelay)), "CheckTime" End If End Sub The code above is set to save & close the workbook if it is idle for more than 10 minutes. It will check every minute. Hope this helps, Hutch "Spencer Hutton" wrote: I use this to Save and close the workbook when the user is idle for 10 minutes: Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim TimeOut As Date TimeOut = Now() + TimeValue("00:10:00") Application.OnTime TimeOut, "KillApp" End Sub Sub KillApp() ThisWorkbook.Save ThisWorkbook.Close End Sub But as soon as the workbook finishes saving and closing, it opens right back up again??? Can anyone help? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Kill a Macro? | Excel Programming | |||
Excel Restarting | Excel Worksheet Functions | |||
Kill Macro | Excel Discussion (Misc queries) | |||
Restarting a macro | Excel Worksheet Functions | |||
How to Kill a vba macro from a Function// | Excel Programming |