Results 1 to 2 of 2

Thread: Timers in Excel

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    92

    Exclamation 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.
    Paul

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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:
    1. [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)
    2.     lngTimeSinceUsed = 0
    3. [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:
    1. [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], _
    2. [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])
    3.     lngTimeSinceUsed = lngTimeSinceUsed  + 1
    4.     Doevents
    5.  
    6.     [color="#0000A0"]If[/color] lngTimeSinceUsed = 10 [color="#0000A0"]Then[/color]
    7.        [color="#00A000"]' Kill Excel & Exit the timer![/color]
    8.     [color="#0000A0"]End[/color] [color="#0000A0"]If[/color]
    9. [color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width