Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill a Macro? Andyjim Excel Programming 3 February 14th 08 10:23 PM
Excel Restarting Teacher Excel Worksheet Functions 0 December 1st 07 07:16 AM
Kill Macro Jeff Excel Discussion (Misc queries) 4 September 27th 06 04:33 PM
Restarting a macro BR Excel Worksheet Functions 19 December 23rd 05 09:57 PM
How to Kill a vba macro from a Function// coco Excel Programming 4 June 24th 05 11:11 PM


All times are GMT +1. The time now is 07:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"