Auto Closing of Spreadsheet

Smithy2k7

New Member
Joined
Aug 14, 2014
Messages
29
Hello,
How do I get a spreadsheet to close automatically after a pre-determined period of time. I have seen code that does this but if I have more than one spreadsheet open it closes down all the spreadsheets and not just the one with the code in.

Is it possible to get Excel to close down only the spreadsheet I need even if I am working in another spreadsheet?

TIA
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Can you post the code that you tried that closes down everything?
My guess is it uses "Application.Quit", which closes that session of Excel.
You probably want something like "ActiveWorkbook.Close" instead, which would just close the ActiveWorkbook.
 
Upvote 0
Can you post the code that you tried that closes down everything?
My guess is it uses "Application.Quit", which closes that session of Excel.
You probably want something like "ActiveWorkbook.Close" instead, which would just close the ActiveWorkbook.
Hello,
The code that is in use is below

Sub closeWB()
If DateDiff("n", lastSelectionChange, Now) > 1 Then
ThisWorkbook.Close SaveChanges:=True
Else
Application.OnTime Now + TimeSerial(0, 1, 0), "closeWb"

End If
End Sub
 
Upvote 0
That code should not close all workbooks.
 
Upvote 0
Yes. If all of them are closing, something else must be behind it.
 
Upvote 0

Forum statistics

Threads
1,215,545
Messages
6,125,455
Members
449,228
Latest member
moaz_cma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top