+ Reply to Thread
Results 1 to 32 of 32

Timer in statusbar since last sheet change

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Timer in statusbar since last sheet change

    I have code that closes my workbook after 1 hour of inactivity (ie no sheet change or event changes)

    What i would love is to have the remaining time left for the user to make such a change (before it closes on them) visible in the statusbar. Any help there?

    Code for ThisWorkbook

    Please Login or Register  to view this content.
    Code for module

    Please Login or Register  to view this content.

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Timer in statusbar since last sheet change

    these will turn on and allow you to display in the status bar and then return the status bar to regular XL...I'm not sure where you want to put this, but hopefully it will get you started...

    Please Login or Register  to view this content.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    judgeh59

    Thanks for that, I know how to put something in the statusbar, I was hoping someone could figure out how to display the timer remaining as per the code above....as I have set the timer for 1 hour, so Excel is counting down from 1 hour , the result of which I want displayed and when the user makes a change or a calculation that timer is reset (by way of the Settimer routine) so you can see exactly how much time is left before the workbook selfcloses.

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Timer in statusbar since last sheet change

    sorry, I wasn't sure exactly which part you were looking for....let me play a bit....

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Timer in statusbar since last sheet change

    one of the hard parts is waiting the minutes to count off .....it think this may get you what you need....

    it actually runs a loop until the hour is up...the DoEvents allows you to "break" out of the loop by doing something like clicking in a cell. It doesn't seem to resource intensive. I didn't test every facet of the process because I'm not sure exactly what you are doing...the only way to manually break out of the loop to do a Ctrl-Break....hope this helps...
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    i get a run tim error 1004 Methos On time of object _Application failed error on opening, referring to

    Please Login or Register  to view this content.
    of the settimer?
    Last edited by nickmax1; 10-21-2014 at 12:09 PM.

  7. #7
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Timer in statusbar since last sheet change

    I'm not really sure on that....I don't get an error and I didn't touch anything that Sub()....weird.....let me try a few things....

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Timer in statusbar since last sheet change

    testing upload.....I file I uploaded on my desktop works fine....BUT, when I open the file I upload from the website, I get the same error. I'm going to try and upload again....If it doesn't work. I'm just post the code....
    Attached Files Attached Files

  9. #9
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Timer in statusbar since last sheet change

    No Joy...

    here is the code

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    I can't see the solution suggested by @judgeh59 coz I'm not at a pc right now, but it sounds like your doing a loop?
    If so, I can suggest an alternate aproach:
    Set up a second timer with the Procedure parameter set to a call back routine that updates the status bar and restarts the second timer - set it to 1 min or 30 sec perhaps. You then need some clean up code to stop the second timer in your shut down routine.


    Sent from my iPad using Tapatalk

  11. #11
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    coolblue - how would you go about that?

    Judgeh59 - sorry i just cant get your code to work without an error!

  12. #12
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    coolblue - how would you go about that?

    Judgeh59 - sorry i just cant get your code to work without an error!
    Like this for example...

    In ThisWorkbook
    Please Login or Register  to view this content.
    In a module
    Please Login or Register  to view this content.
    I made the update 2 sec just so you don't get bored, but I would put it as 60 sec in practice and get rid of the batton thingy...
    Last edited by coolblue; 10-22-2014 at 12:45 PM.

  13. #13
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    not sure i understand your code - how is it reset when a user is active in the sheet? It keeps ticking down no matter what interaction is used.

  14. #14
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    not sure i understand your code - how is it reset when a user is active in the sheet? It keeps ticking down no matter what interaction is used.
    Correct. I'm just establishing the principle for the second timer.
    You need to add the stuff for user activity resetting the timer back in yourself.

  15. #15
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Here is a complete solution in the style I would recomend.

    Architecture
    shutDownTimer.jpg
    (maybe this link will work later... anyway, I added the pic to the attached spreadsheet)

    ThisWorkbook Module
    Please Login or Register  to view this content.
    cShutDownTimer Class Module
    Please Login or Register  to view this content.
    cOnTime Class Module
    Please Login or Register  to view this content.
    cWorkbook Class Module
    Please Login or Register  to view this content.
    modCallBacks Standard Module
    Please Login or Register  to view this content.
    example spreadsheet attached Status Bar 20141023 r1.xlsm
    Last edited by coolblue; 10-24-2014 at 02:07 AM.

  16. #16
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    wow - that is intricate!

    I get an error on opening however - error 1004, method Ontime of application failed.
    referring to:

    Set shutDownTimer = New cShutDownTimer

  17. #17
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    In the spreadsheet I uploaded?


    Sent from my iPhone using Tapatalk

  18. #18
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    yes your spreadsheet delivers an error (i am using excel 2010)

  19. #19
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Timer in statusbar since last sheet change

    Don't open it from the Temp directory when you download it. Save the file to your desktop or one of your own folders and open the spreadsheet from there.
    I don't know what browser your using but select Download File not Open file in your browser.

    Sent from my iPhone using Tapatalk
    Last edited by coolblue; 10-24-2014 at 04:48 AM.

  20. #20
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    aha that solved it (weird i never thought that should be an issue)

    love you code its awesome, WAY beyond my understanding (where in the code does it reset the timer when the user makes an event change?)

    rep added and solved.

  21. #21
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Timer in statusbar since last sheet change

    The path for the file in the browser cache appears to be some kind of abstraction... The folder referenced in the error message does not physically exist. That's why the callback can't be found by Application.OnTime. I never encountered this before and I don't really understand it but if you put yourself in the position if the macro and go looking for the file it says it can't find, then you won't be able to find it either. So it doesn't take long to work out what the problem is.


    Sent from my iPhone using Tapatalk

  22. #22
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    aha that solved it (weird i never thought that should be an issue)

    love you code its awesome, WAY beyond my understanding (where in the code does it reset the timer when the user makes an event change?)

    rep added and solved.
    Thanks for the rep.

    The cWorkbook object is responsible for monitoring activity. It has a custom event called Activity that it raises whenever the various activity-related events in the workbook fire. You can easily customise which events in the cWorkbook object. When a new cWorkbook instance is created, it automatically subclasses whatever is currently "ThisWorkbook". That means any events raised by the ThisWorkbook object will first pass through the cWorkbook object. The subclassing is set up by this code in cWorkbook
    Please Login or Register  to view this content.
    This routine is automatically executed whenever a new instance is created.

    The cShutdownTimer object invokes an instance of cWorkbook here:
    Please Login or Register  to view this content.
    and subsribes to the Activity event here:
    Please Login or Register  to view this content.
    ...and thats where the shutdown timer is reset.

  23. #23
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    wow impressive.

    quick question - the timer is currently set to 1 hour, but changing that to anything less (ie 0.5) kills it instantly. How do I set it for 1 minute, 10 minuites,30 seconds, or 10 seconds etc(for testing purposes)?
    Last edited by nickmax1; 10-24-2014 at 05:28 AM.

  24. #24
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    wow impressive.

    quick question - the timer is currently set to 1 hour, but changing that to anything less (ie 0.5) kills it instantly. How do I set it for 30 seconds, or 10 seconds (for testing purposes)?
    Find this code in the cShutDown object...

    Please Login or Register  to view this content.
    and enter the new value (e.g. 10 for seconds) in the ThisWorkbook Module here...
    Please Login or Register  to view this content.
    Also, add this line to the top of the ThisWorkbook Module if you just want to see a dialog on time-out...
    Please Login or Register  to view this content.

  25. #25
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    ah great that seems to work.

    now i can test to see if it closes, but it doesnt seem to - it gives me the boom! msgbox, but doesnt actually close the workbook?

  26. #26
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    That's how to hack it. To fix it properly, do this...

    In ThisWorkbook Module
    Change this...
    Please Login or Register  to view this content.
    To this...
    Please Login or Register  to view this content.
    In the cShutDownTimer Class Module make these changes...

    Add the CLng in the Class_Initialise sub here...
    Please Login or Register  to view this content.
    And change this...
    Please Login or Register  to view this content.
    To this...
    Please Login or Register  to view this content.
    And Bob's your ankle.

  27. #27
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    ah great that seems to work.

    now i can test to see if it closes, but it doesnt seem to - it gives me the boom! msgbox, but doesnt actually close the workbook?
    Correct, you can customise that behaviour in the ThisWorkbook Module here...
    Please Login or Register  to view this content.
    In fact the whole system is customised in the ThisWorkbook Module here...
    Please Login or Register  to view this content.
    Last edited by coolblue; 10-24-2014 at 05:59 AM.

  28. #28
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    coolblue

    I uncommented the below code hoping it would close the workbook - but to no avail - it just resets the timer again

    Please Login or Register  to view this content.

  29. #29
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    coolblue

    I uncommented the below code hoping it would close the workbook - but to no avail - it just resets the timer again

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    will fix that.

  30. #30
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    thanks...interestingly it does close the workbook (though doesnt show the msgbox, though thats not a big deal) but after closing reopens it?

  31. #31
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Timer in statusbar since last sheet change

    Quote Originally Posted by nickmax1 View Post
    thanks...interestingly it does close the workbook (though doesnt show the msgbox, though thats not a big deal) but after closing reopens it?
    Make this edit in cShutDownTimer...
    Please Login or Register  to view this content.

  32. #32
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Timer in statusbar since last sheet change

    aha that closes it fine thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 12-12-2012, 08:46 PM
  2. change chart data on timer
    By TimTDP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-05-2011, 09:25 AM
  3. Change font color of Application.StatusBar
    By noliveira in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2008, 09:16 AM
  4. how to change to Bold or color font of statusbar
    By newby in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-26-2007, 11:39 PM
  5. [SOLVED] worksheet change on timer
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1