Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to close an excel file automatically if there is no activity for 5 minutes. I have no knowledge how to go about it. I tried to find a answer on Internet but there is no clear answer.

share|improve this question
The only way I can think to do this is to keep track of when the workbook was last used by setting a variable for basically any event... and then using Application.Ontime to have a sub that checks the date in the variable to see if it was last updated 5 or more minutes ago. This solution is far too involved for me to be willing to write it for you though... – Daniel Oct 26 '12 at 16:26
up vote 3 down vote accepted

Google for 'excel close idle timer'. There are multiple complete solutions out there. There's even a tutorial post on this:

-- jm

share|improve this answer

This can be done in VBA. I had done this once before with a shared workbook, but could not find the code I used. What I did find is the following;

Close Workbook after Inactivity

I tested it on my Excel 2010 and it works just fine.

Note: It is referring to the ThisWorkbook object where it says to

Place this in the Workbook_Open event

Keep in mind macros need to be enabled for this to work. Also, the worksheet_change sub needs to be on each sheet you are looking for changes. If not, it will close the sheet even if they are working on another sheet that doesn't have the code.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .