automatic shutoff

stiles12

New Member
Joined
Mar 5, 2009
Messages
1
is there a way to set a timer that will automatically shut excel off if i haven't typed in it, clicked on the page, or typed anything? almost like a screen saver timer that will automatically turn off the monitor if you haven't worked on the computer in a while?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
With some vba, it's possible.

First, put this into the ThisWorkbook Module to start ther time when the book opens:
Rich (BB code):
Private Sub Workbook_Open() 
    EndTime = Now + TimeValue("00:15:00") 
    RunTime 
End Sub
It sets a 15-minute timer, adjust that if desired.

Next, put this code into the Sheet module for every sheet you want to reset your "timer":
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range) 
    If EndTime Then 
        Application.OnTime _ 
        EarliestTime:=EndTime, _ 
        Procedure:="CloseWB", _ 
        Schedule:=False 
        EndTime = Empty 
    End If 
    EndTime = Now + TimeValue("00:15:00") 
    RunTime 
End Sub

The part in red resets a 15-minute timer, so again, change that to the value you want.

Lastly, these macros go in a standard Module and they activate if the timer goes off due to inactivity:
Rich (BB code):
Public EndTime 
Sub RunTime() 
    Application.OnTime _ 
    EarliestTime:=EndTime, _ 
    Procedure:="CloseWB", _ 
    Schedule:=True 
End Sub 
Sub CloseWB() 
    Application.DisplayAlerts = False 
    With ThisWorkbook 
        .Saved = True 
        .Close 
    End With 
Application.OnTime EarliestTime:=TimeValue("17:00:00"), _
    Procedure:="closeWB", Schedule:=False
End Sub

(source)

(more reading)
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,760
Members
449,095
Latest member
m_smith_solihull

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