+ Reply to Thread
Results 1 to 4 of 4

Close excel when inactive

  1. #1
    Registered User
    Join Date
    03-02-2004
    Posts
    15

    Question Close excel when inactive

    Hi,

    I would like to have excel close after 15min of being inactive (no button / mouse clicks, no data entered, etc) however it may still be the active workbook.

    If possible I would like it to bring up a message box that says something along the lines of:

    "About to close, click Cancel to stop." and clicking cancel would keep the workbook open until it had been inactive for another 15 min period.

    Does anyone know how to do this?

    Thanks
    Jennie

  2. #2
    Bob Phillips
    Guest

    Re: Close excel when inactive

    You could use Ontime together with worksheet change event code to monitor
    it.


    There are 5 elements here.


    Firstly have a macro which invokes Ontime to run a macro that shutdown in 15
    minutes. And you also need a macro to reset the timer . SO, in a standard
    code module, add

    Option Explicit


    Public nShutdown As date

    Public Sub SetShutdownTimer()
    nSaveWB = Now + TimeSerial(0, 15, 0) ' 15 minutes
    Application.OnTime nShutdown, "Shutdown"
    End Sub


    Public Sub Shutdown()
    Dim ans
    ans = MsgBox"About to close, click Cancel to stop.", vbOKCancel)
    If vbOK Then
    Application.Quit
    Else
    SetShutdownTimer
    End If
    End Sub

    You then need to set the timer in the first place, when the workbook opens.
    And you also need to trap any workbook changes , and any worksheet
    selectione, so that the timer gets cancelled, and set anew (note this
    doesn't
    reset the timer for any formatting changes, only data changes).


    Option Explicit


    Private Sub Workbook_Open()
    SetShutdownTimer
    End Sub


    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Application.OnTime nShutdown, "Shutdown", , False
    SetSaveWBTimer
    End Sub

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
    As Range) Application.OnTime nShutdown, "Shutdown", , False
    SetSaveWBTimer
    End Sub



    'This is workbook event code.
    'To input this code, right click on the Excel icon on the worksheet
    '(or next to the File menu if you maximise your workbooks),
    'select View Code from the menu, and paste the code



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "jennie" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi,
    >
    > I would like to have excel close after 15min of being inactive (no
    > button / mouse clicks, no data entered, etc) however it may still be
    > the active workbook.
    >
    > If possible I would like it to bring up a message box that says
    > something along the lines of:
    >
    > "About to close, click Cancel to stop." and clicking cancel would keep
    > the workbook open until it had been inactive for another 15 min
    > period.
    >
    > Does anyone know how to do this?
    >
    > Thanks
    > Jennie
    >
    >
    > --
    > jennie
    > ------------------------------------------------------------------------
    > jennie's Profile:

    http://www.excelforum.com/member.php...fo&userid=6706
    > View this thread: http://www.excelforum.com/showthread...hreadid=490678
    >




  3. #3
    Registered User
    Join Date
    03-02-2004
    Posts
    15
    Thanks a lot

    I will give it a try

    Thanks
    Jennie

  4. #4
    Benoit Lamarche
    Guest

    Re: Close excel when inactive


    I think it should be:

    ans = MsgBox("About to close, click Cancel to stop.", vbOKCancel)

    (missing a bracket)

    Also, when I try to run the code, I get:

    nSaveWB (variable not defined)

    and also, after trying to run "Public Sub Shutdown"

    I get "Only comments may appear after End Sub ..."

    All the code is in the worksheet's property, is that what's intended?


    --
    Benoit Lamarche


    "Bob Phillips" wrote:

    > ...
    > Public Sub Shutdown()
    > Dim ans
    > ans = MsgBox"About to close, click Cancel to stop.", vbOKCancel)
    > If vbOK Then
    > Application.Quit
    > Else
    > SetShutdownTimer
    > End If
    > End Sub



+ Reply to 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