Consulting

Results 1 to 3 of 3

Thread: Auto shut down of spreadsheet if inactive.

  1. #1
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location

    Auto shut down of spreadsheet if inactive.

    Hi,

    I know this is being a wee bit nasty, but still it is something that I need to do.

    I have created a spreadsheet to collate the absence levels within my department.

    I made this file open to anyone who knows the password.

    What I have now found is that some people go into the program, do their stuff and then walk away leaving it active on their screen. Screensaver will then kick in which is password protected.

    I don't want to actively share the workbook as I don't feel that it works properly for what I am doing.

    So heres the deal - is there a way I can build in an automatic shutdown of the program/spreadsheet if the user hasn't touched it for a period of time?

    I would be nice and try set it for at least half an hour, but it would have to save and exit the program.

    Any takers?

    Hoopsah
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Option Explicit

    '-----------------------------------------------------------------
    Private Sub Workbook_Open()
    '-----------------------------------------------------------------
    nElapsed = TimeSerial(0, 30, 0) '30 minutes
    'start a timer to countdown inactivity
    Application.OnTime Now + nElapsed, "Closedown"
    End Sub

    '-----------------------------------------------------------------
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    '-----------------------------------------------------------------
    'close the timer
    Application.OnTime Now + nElapsed, "Closedown",,False
    End Sub

    '-----------------------------------------------------------------
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    '-----------------------------------------------------------------
    'any workbook activity resets the timer
    Application.OnTime Now + nElapsed, "Closedown"
    End Sub
    [/vba]

    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



    Put this code in a standard code module

    [vba]

    Option Explicit

    Public nElapsed As Double

    '-----------------------------------------------------------------
    Sub Closedown()
    '-----------------------------------------------------------------
    ThisWorkbook.Close SaveChanges:=True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor Hoopsah's Avatar
    Joined
    Nov 2007
    Posts
    303
    Location
    Hi Bob,

    sorry about the delay on this one but I have been away from my desk for a couple of weeks.

    Will try it out soon and let you know how I got on,

    Cheers

    Gerry
    I am playing all the right notes, but not necessarily in the right order.
    Eric Morecambe

Posting Permissions

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