+ Reply to Thread
Results 1 to 13 of 13

Message displayed after automatically closing down a workbook

  1. #1
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Message displayed after automatically closing down a workbook

    Hi everybody!

    For automatically closing down a workbook for 2 minutes of inactivity, I use these codes:

    For the common module:

    Please Login or Register  to view this content.
    And for ThisWorkbook:

    Please Login or Register  to view this content.
    After closing down, it still remains a blank window of the excel, where I'd like to pop-up a message box for the users to let them know that the workbook got closed (e.g. "File closed for 2 minutes of inactivity")

    Please, can someone help me with this?

    Thanks!

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Message displayed after automatically closing down a workbook

    Try

    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Message displayed after automatically closing down a workbook

    Hi Lewis!
    I need to have a message displayed after closing down.
    Last edited by boboivan; 02-18-2014 at 10:02 AM.

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

    Re: Message displayed after automatically closing down a workbook

    I think it's not possible once the wkb is closed...
    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-

  5. #5
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Message displayed after automatically closing down a workbook

    @John55

    I'm thinking that if it still remains a blank window of the excel, it could be possible to popup a message though.

  6. #6
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Message displayed after automatically closing down a workbook

    Your vba is in the workbook. If you close the workbook, there is no vba. You need to use an external application. The task scheduler can create popups, use that before closing your workbook.

    You would have vba write the scheduled tasked in commandline and run it before closing.

  7. #7
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Message displayed after automatically closing down a workbook

    @Slx
    Thank you for your detailed answer. Makes sense everything you said.

    Unfortunately I'm not very good with VBA. Is there anything you can do improve the existing codes?

    Thx in advance!
    Last edited by boboivan; 02-18-2014 at 10:42 AM.

  8. #8
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Message displayed after automatically closing down a workbook

    If you want to learn how to do more with vba, like making an external pop up. I would suggest you give it a try, use command line and what you want to input is the scheduled task.

    Command line -> http://social.technet.microsoft.com/...ba?forum=excel
    Scheduled task -> http://technet.microsoft.com/en-us/l...px#BKMK_create


    Alternatively, you could just use msgbox and application.quit afterwards. This way the person will see the message and when they exit the message box the system will goto the next step which is close. Close as smoothly as possible, you would save, then msgbox and close with no save.

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Message displayed after automatically closing down a workbook

    Sorry, Lewis can't read. I missed the part about the pop-up window.
    I believe john55 is correct. Once the file is closed, ALL MACRO activity associated with the file stops.


    You may be able to do what you want using 'wscript' built into many windows systems. The following code excerpts worked with Excel 2003 and a Vista 64 bit system.

    Create a file called PopUpMessage.vbs
    Please Login or Register  to view this content.

    Termination code excerpt (tested and working):
    Please Login or Register  to view this content.
    Lewis
    Last edited by LJMetzger; 02-18-2014 at 10:57 AM.

  10. #10
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Message displayed after automatically closing down a workbook

    Quote Originally Posted by slx View Post
    If you want to learn how to do more with vba, like making an external pop up. I would suggest you give it a try, use command line and what you want to input is the scheduled task.

    Command line -> http://social.technet.microsoft.com/...ba?forum=excel
    Scheduled task -> http://technet.microsoft.com/en-us/l...px#BKMK_create


    Alternatively, you could just use msgbox and application.quit afterwards. This way the person will see the message and when they exit the message box the system will goto the next step which is close. Close as smoothly as possible, you would save, then msgbox and close with no save.
    Thank you so much Slx!

  11. #11
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Message displayed after automatically closing down a workbook

    Quote Originally Posted by LJMetzger View Post
    Sorry, Lewis can't read. I missed the part about the pop-up window.
    I believe john55 is correct. Once the file is closed, ALL MACRO activity associated with the file stops.


    You may be able to do what you want using 'wscript' built into many windows systems. The following code excerpts worked with Excel 2003 and a Vista 64 bit system.

    Create a file called PopUpMessage.vbs
    Please Login or Register  to view this content.

    Termination code excerpt (tested and working):
    Please Login or Register  to view this content.
    Lewis
    Thank you so much Lewis!
    Works great!
    Last edited by boboivan; 02-18-2014 at 11:52 AM.

  12. #12
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Message displayed after automatically closing down a workbook

    Here's a similar solution using Windows API GetCursorPos() to determine inactivity. I was unable to find an API 'Mouse Move Event' so instead a timer is used to poll the cursor position every few seconds. When a timeout occurs, the file is saved, a wscript message is displayed, and Excel is terminated just like in the previous post.

    The following items at the top of 'ModCursorMovement' can be changed to fine tune 'Lack of Cursor Movement Detection':
    a. Conditional Compilation Constant 'NEED_TO_DEBUG' - Set 'True' for PRODUCTION and set to 'False' for SOFTWARE DEVELOPMENT.
    b. Const 'jDeltaMaxForNoMOVEMENT' to determine 'cursor position sensitivity (e.g. 5 means Delta of 5 pixels means position DID NOT MOVE).
    c. Const 'jMaxSecondsOfInactivityALLOWED' to determine TIMEOUT VALUE (e.g. 120 seconds is 2 minutes).
    d. Const 'jSecondsBetweenSAMPLES' to determine how often the cursor position is sampled.

    When in SOFTWARE DEVELOPMENT mode the debugger 'Immediate Window' (CTRL G) contains POSITION data.

    Code follows and is included in the attached file.

    Lewis

    ThisWorkbook Module:
    Please Login or Register  to view this content.
    Ordinary Module ModCursorMovement:
    Please Login or Register  to view this content.
    Ordinary Code modeule LjmTimers:
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    02-12-2013
    Location
    Brussel
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Message displayed after automatically closing down a workbook

    Thank you for the codes and for your kind support!

    Everything works just fine, but if I have a user that doesn't use the mouse but only the keyboard, the workbook closes down.
    Anything that can be done with this problem? I'm thinking of a mixture between the original codes I'm using now (see my first post) and these ones .

  14. #14
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Message displayed after automatically closing down a workbook

    Hi,

    I incorporated Workbook events similar to your original post to reset the Inactivity counter when a keystroke is entered that moves the focus to a different cell. I tried to trap every keystroke, but the solution I tried did not seem reliable.

    I also added the ability to open the worksheet to a specific 'Sheet' and 'Cell'. This capability is enabled
    ONLY by 'Automatic Save' at this time.

    Since I can't trap individual keystrokes, the following items are known not to be detected:
    a. Excel Menu item keystrokes
    b. Add a sheet
    c. Rename a sheet

    Please let me know if I have overlooked anything. This worksheet is similar to the previous file. The default timeout is currently set to 10 seconds.

    Lewis

+ 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. Macro to display a message before closing workbook
    By robertguy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-11-2016, 01:32 AM
  2. Pop-up message appear when closing workbook
    By cooh23 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 05-06-2013, 01:52 PM
  3. Closing a Message Box Automatically
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-01-2013, 02:57 PM
  4. Replies: 1
    Last Post: 07-12-2006, 05:48 PM
  5. Automatically closing workbook
    By zapszipszops in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2006, 11:50 AM

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