+ Reply to Thread
Results 1 to 4 of 4

Excel Idle Time Close

Hybrid View

  1. #1
    Registered User
    Join Date
    02-12-2007
    Posts
    1

    Excel Idle Time Close

    I need to set some type of function that will save & close a spreadsheet if it is left unattended for a certain amount of time.

    Is there an option for this or do i need to create a macro?

    Any help would be great. Thanks.

  2. #2
    Forum Contributor
    Join Date
    01-24-2007
    Location
    Southampton, UK
    Posts
    137
    There is no option within Excel to automatically time out. Windows itself has a time out facility - by using a screen saver and setting the on resume display welcome screen item (in XP) you can force users to re-login when there has been no activity on the PC.

    For Excel in particular, you could set up code to detect when the Workbook has been inactive. Try the following ....

    Copy and paste the following into the ThisWorkbook module -

    Option Explicit
    
    Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    ResetTimer
    End Sub
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    ResetTimer
    End Sub
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    ResetTimer
    End Sub
    This simply checks whenever the workbook is active and resets a timer.

    Then copy and paste the following into a user module -


    Public CloseDownTime As Variant
    
    Public Sub ResetTimer()
    On Error Resume Next
    If Not IsEmpty(CloseDownTime) Then Application.OnTime EarliestTime:=CloseDownTime, Procedure:="CloseDownFile", Schedule:=False
    CloseDownTime = Now + TimeValue("00:00:30") ' hh:mm:ss
    Application.OnTime CloseDownTime, "CloseDownFile"
    End Sub
    
    Public Sub CloseDownFile()
    On Error Resume Next
    Application.StatusBar = "Inactive File Closed: " & ThisWorkbook.Name
    ThisWorkbook.Close SaveChanges:=True
    End Sub
    Change the green highlighted part "00:00:30" above to whatever interval you need (currently this is set for 30 seconds).

    The Application.StatusBar = item is optional - it simply leaves a message for the user at the bottom of the Excel screen, which will remain until Excel is closed down and re-started.
    Last edited by Loz; 05-02-2007 at 05:05 AM.

  3. #3
    Forum Contributor
    Join Date
    10-23-2014
    Location
    Kolding, Denmark
    MS-Off Ver
    MS Office 2010
    Posts
    169

    Re: Excel Idle Time Close

    I can only get it to it the first time.. ??

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,047

    Re: Excel Idle Time Close

    Mettegaga, welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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