+ Reply to Thread
Results 1 to 20 of 20

Close workbook due to inactivity.

  1. #1
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Close workbook due to inactivity.

    RoyUK has shown it can be done, the problem comes in where he gave an excel workbook as an example of what he was showing, it has been deleted...

    http://www.excelforum.com/excel-prog...nactivity.html

    Is there a way to resurrect this worksheet, or upload a new one to show as an example of how this work? I've read his script, and without knowing how he put it in a sheet I'm not sure how to make it work.

    Thanks

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Close workbook due to inactivity.

    I've re-built it for you
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    The first routine goes in a standard module. The other two go in the Workbook Class module (double click on the wb in the VBE.)


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    Quote Originally Posted by royUK View Post
    I've re-built it for you
    Thanks that is greatly appreciated

    I opened the worksheet and it told me that there is a Run-time error '1004':

    Method 'OnTime' of object '_Application' failed... at here:

    Please Login or Register  to view this content.
    Last edited by Cyberpawz; 06-08-2012 at 12:22 PM.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Close workbook due to inactivity.

    That's strange because it works fine on my PC.

    Just remove the line splits & see if that is the problem

  6. #6
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    I restarted the computer, the error went away.

    Thanks again

    I do have a question, I see that there is a 5:00 clock on one setting, and a 10:00 clock on another, is there a reason for that? Can they both be the same?
    Last edited by Cyberpawz; 06-08-2012 at 01:27 PM.

  7. #7
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    I got an error, saying it couldn't save my file because it didn't exist, it looks for some reason it is attempting to save the file... here is the image of the error:

    Error.Jpg

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    Works fine for me. In fact, unless you save your work as you go along, the code is designed to close without saving the workbook.

    Try downloading it to a folder somewhere and running it from there.

    Regards, TMS

  9. #9
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    Ok, got it working on the close aspect, but not the saving. I type something in the file and when it closes it doesn't save... I know this because when I open the document again the change I did isn't there.

  10. #10
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Close workbook due to inactivity.

    if you want to save automatically when you close the file try this
    Please Login or Register  to view this content.
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    Read my last post ... by design.

    If you want to use this approach, you will need to save your data as you go.

    Alternatively, take out the .Saved and just Close the workbook. It will, however, sit waiting for the close request to be assessed and actioned ... that is, save or don't.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    If you take John's advice, you may commit changes that were not intended to be made permanent.

    But, the choice is yours. Save as you go, force the save, or wait for action.

  13. #13
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    Solved it, changed a part:

    Please Login or Register  to view this content.
    it works now.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    That may commit changes you had not intended ...

  15. #15
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    Quote Originally Posted by TMShucks View Post
    That may commit changes you had not intended ...

    No, but it will teach people good practices. That being said I am running into an issue. The sheet even if I am typing in it saves and shuts down. It looks like the timer doesn't reset itself.

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Close workbook due to inactivity.

    There's no point in the With Thisworkbook statement in your last code snippet, you still use ThisWorkbook.Close

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    Have you got the change event in every sheet?

    It needs to recognise any changes you make. Equally, a selection change would probably work ... It at least means someone is looking at the data, even if they're not changing it.

    Regards, TMS

  18. #18
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    Quote Originally Posted by TMShucks View Post
    Have you got the change event in every sheet?

    It needs to recognise any changes you make. Equally, a selection change would probably work ... It at least means someone is looking at the data, even if they're not changing it.

    Regards, TMS
    How would you do that? Because isn't the purpose of putting the code in ThisWorkbook mean to deal with all sheets in the workbook in the first place?
    Last edited by Cyberpawz; 06-11-2012 at 04:14 PM.

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Close workbook due to inactivity.

    It should be OK if you have this in the Workbook module:

    Please Login or Register  to view this content.

    That monitors changes in every worksheet. I think that it resets the time.

    So, maybe you could add:

    Please Login or Register  to view this content.

    ... should monitor any movement on the sheets.


    Regards, TMS

  20. #20
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Close workbook due to inactivity.

    Sorry it took so long to read this, but this is my code:

    Please Login or Register  to view this content.
    Yours is not much different than what I have... I can't figure out why this isn't working. This script is in ThisWorkbook.
    Last edited by Cyberpawz; 06-21-2012 at 11:03 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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