Returning Home

JasonBing

New Member
Joined
Aug 6, 2019
Messages
49
Is there a way to get a workbook to activate a certain worksheet, say Sheet1 "A1" after a set period of inactivity?


Thanks

Jason Bing


EDIT: I know you can get a workbook to save and close after inactive time. But I need it to return to a home page?
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Ok, slightly different approach
This in a standard module

Code:
Option Explicit
Public LastActivityTime As Date
Sub Check_Inactivity2()
    Const Inactivity_Delay As Date = #12:01:00 AM# ' currently set for one minute
    If LastActivityTime + Inactivity_Delay < Now() Then
        Sheets("Sheet1").Activate
        Range("A1").Select
    Else
        Application.OnTime LastActivityTime + Inactivity_Delay, "Check_Inactivity2"
        End If
    End Sub

This in the "ThisWorkbook" module

Code:
Option Explicit
Private Sub Workbook_Open()
    LastActivityTime = Now()
    Check_Inactivity2
    End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    LastActivityTime = Now()
    End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    LastActivityTime = Now()
    End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    LastActivityTime = Now()
    End Sub
 
Upvote 0
@JasonBing

- did you save, close and reopen the workbook?
- opening the workbook is the "trigger" which gets things running
 
Upvote 0
Thanks for the reply’s. Will test when I get back to the office. Yes I did save exit and RE open. Thanks for the input.

Regards

Jason bing
 
Upvote 0
The code worked beautifully on the test workbook and on the master project. Little problem though, it only works once!

To get it to work again you have to close the workbook and reopen it. Then it will work again, once.

Awesome bit of code though I am impressed, I did some testing also and it doesn't seem to make a difference if autosave is on or off still works

Thanks again for your help. This id definitely above my pay grade. I am in awe

Regards

Jason Bing
 
Upvote 0
If you want it to work all the time it would mean the code would be working ALL the time, but it can be done.
Is that what you want ??
 
Upvote 0
Ok, replace the Check_Inactivity2 code with this one

Code:
Option Explicit
Public LastActivityTime As Date
Sub Check_Inactivity2()
    Const Inactivity_Delay As Date = #12:01:00 AM# ' currently set for one minute
    If LastActivityTime + Inactivity_Delay < Now() Then
        Sheets("Sheet1").Activate
        Range("A2").Select
        Range("A1").Select
     Application.OnTime LastActivityTime + Inactivity_Delay, "Check_Inactivity2"
Else
        Application.OnTime LastActivityTime + Inactivity_Delay, "Check_Inactivity2"
        End If
    End Sub
 
Upvote 0
Thanks for the reply. Testing the code everything seemed to work great. I would navigate to another sheet, leave it and it returned to sheet 1, after the allotted time. However if the workbook is sitting on sheet 1, after the allotted time Excel becomes non responsive.


Thanks again

Jason Bing
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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