|
-
Mar 17th, 2003, 10:15 AM
#1
Thread Starter
Lively Member
Timers in Excel
Hi All,
I am wanting a timer to run in Excel, which starts running when the user stops using the spreadsheet. After 10 minutes, the timer will automatically close the workbook.
I have the code for the timer (using API), but am struggling to find a way whereby you know that the user is no longer using the sheet.
I have thought of "keydown" or similar, but this would have to be entered into each sheet I think (a bit messy).
I have looked through the options from "This workbook", but none relate to Excel loosing focus.
Can anyone help me please?!?!
Cheers,
Paul.
-
Mar 17th, 2003, 10:32 AM
#2
There is going to be no 'tidy' way to do this, though there is a 'SheetChange' event found under the Workbook module:
Occurs when cells in any worksheet are changed by the user or by an external link.
Personally I would have maybe something like this scenario:
VB Code:
[color="#0000A0"]Private[/color] [color="#0000A0"]Sub[/color] Workbook_SheetChange([color="#0000A0"]ByVal[/color] Sh [color="#0000A0"]As[/color] [color="#0000A0"]Object[/color], [color="#0000A0"]ByVal[/color] Target [color="#0000A0"]As[/color] Range)
lngTimeSinceUsed = 0
[color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]
With this in the timer (possibly using the settimer API call set at a minute interval):
VB Code:
[color="#0000A0"]Sub[/color] TimerProc([color="#0000A0"]ByVal[/color] hwnd [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color], [color="#0000A0"]ByVal[/color] nIDEvent [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color], _
[color="#0000A0"]ByVal[/color] uElapse [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color], [color="#0000A0"]ByVal[/color] lpTimerFunc [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color])
lngTimeSinceUsed = lngTimeSinceUsed + 1
Doevents
[color="#0000A0"]If[/color] lngTimeSinceUsed = 10 [color="#0000A0"]Then[/color]
[color="#00A000"]' Kill Excel & Exit the timer![/color]
[color="#0000A0"]End[/color] [color="#0000A0"]If[/color]
[color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|