change sheet automatically

annadinesh

Board Regular
Joined
Mar 1, 2017
Messages
128
Office Version
  1. 2019
Platform
  1. Windows
1 have 3 sheets

SHEET 1. Details
SHEET 2. SOT
SHEET 3. EW

I want if active sheet was EW or SOT, then it should automatically return to sheet 1 after 30 Sec of inactivity

Regards


Dinesh Saha
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
This can (only) be done with VBA.
Save your workbook as *.xlsm (Macro-enabled Workbook) and open the VBA Editor by pressing [ALT]+[F11], then set up as follows:

Display the Project Explorer

1732967626681.png


right-click on your workbook

1732967555131.png


insert a new Module

1732967691684.png


1732967744002.png


paste the following code into the new module
VBA Code:
Public IdleTime

Sub SwitchSheet()
   ThisWorkbook.Sheets("Details").Activate
End Sub

Sub StartTimer()
   IdleTime = Now + TimeValue("00:01:30")
   Application.OnTime IdleTime, "SwitchSheet"
End Sub

Sub StopTimer()
   On Error Resume Next
   Application.OnTime IdleTime, "SwitchSheet", , False
End Sub

Paste this to the Worksheet section of Sheet1 (Details)
VBA Code:
Private Sub Worksheet_Deactivate()
   Call StopTimer
   Call StartTimer
End Sub
1732967832613.png


Paste this to the Workbook Code
VBA Code:
Private Sub Workbook_Open()
   Call StartTimer
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
   Call StopTimer
   Call StartTimer
End Sub

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
   Call StopTimer
   Call StartTimer
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
   Call StopTimer
   Call StartTimer
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
   Call StopTimer
   Call StartTimer
End Sub

1732967977130.png


If you have any questions let me know
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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