Could you help me update macro to close after 2 minutes of inactivity

Sean15

Well-known Member
Joined
Jun 25, 2005
Messages
722
Office Version
  1. 2010
Platform
  1. Windows
This macro is intended to close the worksheet after 2 minutes of inactivity. However, I’ve observed that when I copy only data or text to paste into another worksheet (as shown in Figure 1), the macro doesn’t close the worksheet after the 2 minutes of inactivity. On the other hand, if I copy the entire cell (see Figure 2), the macro functions as expected and closes the worksheet after 2 minutes. Could you please update the macro so that it will close the worksheet regardless of whether I copy just the text or the entire cell? Thank you.

Sean


VBA Code:
Dim CloseTime As Date

Sub TimeSetting()
    Workbooks("PW 065852").Activate
    Application.CutCopyMode = False
    CloseTime = Now + TimeValue("00:02:00")
    On Error Resume Next
    Application.OnTime EarliestTime:=CloseTime, _
      Procedure:="SavedAndClose", Schedule:=True
End Sub
Sub TimeStop()
    On Error Resume Next
    Application.OnTime EarliestTime:=CloseTime, _
      Procedure:="SavedAndClose", Schedule:=False
 End Sub
Sub SavedAndClose()
    ThisWorkbook.Close Savechanges:=True
End Sub
 

Attachments

  • Figure 1.PNG
    Figure 1.PNG
    56.9 KB · Views: 6
  • Figure 2.PNG
    Figure 2.PNG
    1.7 KB · Views: 6

Forum statistics

Threads
1,226,867
Messages
6,193,428
Members
453,799
Latest member
shanley ducker

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