+ Reply to Thread
Results 1 to 8 of 8

Automatically shutdown and save file if idle for more than 15 minutes

  1. #1
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    104

    Automatically shutdown and save file if idle for more than 15 minutes

    Dear Excel Gurus,

    Below is the working VBA but I want an improvement. I want to add a code that if the file is idle for 15 minutes or more, it will automatically CLOSE and SAVE the file. The below code is written at “ThisWorkbook”.

    Any help would be appreciated.

    Thank you.

    Here is the code.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    Try it like this, with all code in the ThisWorkbook's codemodule except as noted:

    Add a new public variable "dteTimeToClose" to store the time to close and a selection change event that re-schedules the closure based on the selection being changed

    Please Login or Register  to view this content.
    Add this to the Private Sub Workbook_Open() routine to initially schedule the close macro

    Please Login or Register  to view this content.
    And then add this Sub to a standard codemodule to actually save and close the workbook:

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-24-2024 at 04:10 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    Thanks Bernie for your prompt response.

    I include on my VBA code but it does not have any response at all. Please check which error I have. I am a newbie on VBA.

    Here is the code that you ask me to incorporate.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    The attached is set to auto-close after 1 minute - for testing. See the code comments for where to change that time.

    Note that the code is split between two code modules - one standard and the other is the ThisWorkbook's codemodule.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    Thank a lot Bernie,

    The sample file works fine, the code is shutting down after the assign time (1 minute per sample) BUT it shut down even if I am working on the file. My purpose is to shut down when the file is idle for the assign (1 minute per sample) time.

    Again, please help.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    The code to delay the shutdown is in the selection change event, which means that the cell selection needs to be changed within the time frame of your idle window. So if you don't do anything except, say, type in a cell for a minute, then the workbook will be closed.

    When you say "working on the file" what does that mean? We may be able to choose a different event but a lot depends on how you interact with the workbook.

  7. #7
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    That's is what I'm doing, tried to do some entry on the cells but still shutdown after the elapsed time. The "working on the file" is the Excel file with macros you sent.

    Thanks

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Automatically shutdown and save file if idle for more than 15 minutes

    Sorry - I didn't look closely enough at all your code and you have

    Please Login or Register  to view this content.
    in the workbook open event. That disables the code that reschedules the close macro - so just take that line out and it will work fine.

    One other change - when the thumb drive is not attached, the macro may not get scheduled again, so change to this:

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-27-2024 at 09:05 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 10-01-2020, 10:36 PM
  2. [SOLVED] I want to run macro when workbook is idle for N minutes
    By chrismeeky in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2018, 04:32 AM
  3. [SOLVED] timed shutdown (when Idle) with countdown.
    By Kramxel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-29-2014, 04:24 AM
  4. Macro code to automatically save and exit after 2 minutes!
    By Garth2014 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2014, 11:03 PM
  5. Vba Code to Lock the desktop if idle for 5 minutes
    By dasanb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2013, 08:40 AM
  6. [SOLVED] Userform idle for 1 minutes , how to close Workbook linked to it ?
    By stevnb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-04-2012, 09:05 AM
  7. Macro to save automatically excel sheet in every 2 minutes
    By bittu2010 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2012, 11:14 AM

Tags for this Thread

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