Closed Thread
Results 1 to 5 of 5

Idle timeout

  1. #1
    Jesse
    Guest

    Idle timeout

    Can anyone point me to a reference for coding an idle timer? I have a
    submission tool that multiple users access that I want to put an idle
    timer on so that after a certain amount of time it gives a warning and
    to long and it automatically closes the workbook.

    Jesse


  2. #2
    Tom Ogilvy
    Guest

    RE: Idle timeout

    see Chip Pearson's page on using Ontime

    http://www.cpearson.com/excel/ontime.htm

    you could combine this with a selectionchange event to cancel the currently
    scheduled event and schedule a new one.

    http://www.cpearson.com/excel/events.htm if you are not familiar with
    events.

    --
    Regards,
    Tom Ogilvy


    "Jesse" wrote:

    > Can anyone point me to a reference for coding an idle timer? I have a
    > submission tool that multiple users access that I want to put an idle
    > timer on so that after a certain amount of time it gives a warning and
    > to long and it automatically closes the workbook.
    >
    > Jesse
    >
    >


  3. #3
    Jesse
    Guest

    Re: Idle timeout

    Thanks Tom, that will work perfectly.

    Jesse


  4. #4

    Re: Idle timeout

    On Thu, 6 Apr 2006 12:10:02 -0700, Tom Ogilvy
    <[email protected]> wrote:

    >see Chip Pearson's page on using Ontime
    >
    >http://www.cpearson.com/excel/ontime.htm
    >
    >you could combine this with a selectionchange event to cancel the currently
    >scheduled event and schedule a new one.
    >
    >http://www.cpearson.com/excel/events.htm if you are not familiar with
    >events.


    I found this helpful too, thanks. I would like to take this in a
    slightly different direction and detect when a user is no longer idle.
    I thought I had the answer by using the above, to wit:

    Workbook_Open() contains:

    Option Explicit
    Option Base 1

    Dim AppClass As New EventClass

    Private Sub Workbook_Open()
    Set AppClass.App = Application

    End Sub

    and I have a Class Module named "EventClass" with things like this in
    it:

    Option Explicit

    Public WithEvents App As Application

    Private Sub App_NewWorkbook(ByVal Wb As Excel.Workbook)
    MsgBox "NewWorkbook: " & Wb.Name
    bStopFetchingFlag = True 'If we're fetching, this stops us after
    the current one
    SetNewTimer
    End Sub

    Private Sub App_SheetActivate(ByVal Sh As Object)
    MsgBox "Sheet Activated: " & Sh.Name
    bStopFetchingFlag = True
    SetNewTimer
    End Sub

    and then another module containing:

    Sub SetNewTimer()
    ResetTimer 'Cancel any existing timer before starting a new one
    'adjust the time below to your needs, this is 30 minutes
    dNextTime = Now + TimeValue("00:30:00")
    Application.OnTime dNextTime, "DoThings"
    End Sub
    Sub ResetTimer()
    Application.OnTime dNextTime, "DoThings", False
    End Sub

    Sub DoThings()
    Dim i As Long
    For i = 1 To 100000
    DoEvents
    If bStopFetchingFlag Then
    MsgBox "We were stopped!"
    End If
    Next i
    End Sub

    The trouble is, once "DoThings" starts, the bStopFetchingFlag variable
    never becomes true, even though I add sheets, activate sheets, change
    sheets, etc. - all the events I trap for in EventClass.

    Obviously, DoThings above is just a testing routine - the one I
    actually want to use is much more complicated, but I want to stop it
    (while remembering how far it got), in case the user comes back and
    wants to do some other Excel work. My stuff would be packaged in an
    add-in.

    Many things for any help anyone can provide.


  5. #5

    Re: Idle timeout

    On Wed, 19 Apr 2006 10:59:20 -0400, [email protected] wrote:

    >On Thu, 6 Apr 2006 12:10:02 -0700, Tom Ogilvy
    ><[email protected]> wrote:
    >
    >>see Chip Pearson's page on using Ontime
    >>
    >>http://www.cpearson.com/excel/ontime.htm
    >>
    >>you could combine this with a selectionchange event to cancel the currently
    >>scheduled event and schedule a new one.
    >>
    >>http://www.cpearson.com/excel/events.htm if you are not familiar with
    >>events.

    >
    >I found this helpful too, thanks. I would like to take this in a
    >slightly different direction and detect when a user is no longer idle.
    >I thought I had the answer by using the above, to wit:
    >
    >Workbook_Open() contains:
    >
    >Option Explicit
    >Option Base 1
    >
    >Dim AppClass As New EventClass
    >
    >Private Sub Workbook_Open()
    >Set AppClass.App = Application
    >
    >End Sub
    >
    >and I have a Class Module named "EventClass" with things like this in
    >it:
    >
    >Option Explicit
    >
    >Public WithEvents App As Application
    >
    >Private Sub App_NewWorkbook(ByVal Wb As Excel.Workbook)
    >MsgBox "NewWorkbook: " & Wb.Name
    > bStopFetchingFlag = True 'If we're fetching, this stops us after
    >the current one
    > SetNewTimer
    >End Sub
    >
    >Private Sub App_SheetActivate(ByVal Sh As Object)
    >MsgBox "Sheet Activated: " & Sh.Name
    > bStopFetchingFlag = True
    > SetNewTimer
    >End Sub
    >
    >and then another module containing:
    >
    >Sub SetNewTimer()
    > ResetTimer 'Cancel any existing timer before starting a new one
    >'adjust the time below to your needs, this is 30 minutes
    > dNextTime = Now + TimeValue("00:30:00")
    > Application.OnTime dNextTime, "DoThings"
    >End Sub
    >Sub ResetTimer()
    > Application.OnTime dNextTime, "DoThings", False
    >End Sub
    >
    >Sub DoThings()
    > Dim i As Long
    > For i = 1 To 100000
    > DoEvents
    > If bStopFetchingFlag Then
    > MsgBox "We were stopped!"
    > End If
    > Next i
    >End Sub
    >
    >The trouble is, once "DoThings" starts, the bStopFetchingFlag variable
    >never becomes true, even though I add sheets, activate sheets, change
    >sheets, etc. - all the events I trap for in EventClass.
    >
    >Obviously, DoThings above is just a testing routine - the one I
    >actually want to use is much more complicated, but I want to stop it
    >(while remembering how far it got), in case the user comes back and
    >wants to do some other Excel work. My stuff would be packaged in an
    >add-in.
    >
    >Many things for any help anyone can provide.


    OK, I'll reply to my own post in the hope it will help others who find
    this on a Google search or somesuch.

    I suspect my problem was two-fold: First, I was not disabling events
    once I got an event, so I may been having a recursion problem; and,
    second, I had the syntax wrong on some of my Application events, so
    they were never firing. Here's what I ended up doing for "DoThings":

    Sub DoThings()
    Dim i As Long
    On Error GoTo ErrXIT
    For i = 1 To 100000
    DoEvents
    If bStopFetchingFlag Then
    Application.EnableEvents = False
    MsgBox "We were stopped!"
    bStopFetchingFlag = False
    Exit For
    End If
    Next i
    ErrXIT:
    Application.EnableEvents = True
    End Sub

    And, finally, here's the whole list of Application events:

    Option Explicit

    Public WithEvents App As Application

    Private Sub App_NewWorkbook(ByVal Wb As Excel.Workbook)
    bStopFetchingFlag = True 'If we're fetching, this stops us after
    the current one
    SetNewTimer
    End Sub
    Private Sub App_SheetActivate(ByVal Sh As Object)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App__SheetBeforeDoubleClick(ByVal Sh As Object, _
    ByVal Target As Range, Cancel As Boolean)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, _
    ByVal Target As Range, Cancel As Boolean)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_SheetCalculate(ByVal Sh As Object)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_SheetChange(ByVal Sh As Object, _
    ByVal Target As Range)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_SheetDeactivate(ByVal Sh As Object)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_SheetSelectionChange(ByVal Sh As Object, ByVal Target
    As Excel.Range)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WindowActivate(ByVal Wb As Excel.Workbook, ByVal Wn As
    Excel.Window)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WindowDeactivate(ByVal Wb As Excel.Workbook, ByVal Wn
    As Excel.Window)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WindowResize(ByVal Wb As Excel.Workbook, ByVal Wn As
    Excel.Window)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookActivate(ByVal Wb As Excel.Workbook)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookAddInInstall(ByVal Wb As Workbook)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookAddInUninstall(ByVal Wb As Workbook)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As
    Boolean)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookBeforePrint(ByVal Wb As Workbook, Cancel As
    Boolean)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal
    SaveAsUi As Boolean, Cancel As Boolean)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookDeactivate(ByVal Wb As Workbook)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookNewSheet(ByVal Wb As Workbook, ByVal Sh As
    Object)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub
    Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
    bStopFetchingFlag = True
    SetNewTimer
    End Sub


Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1