+ Reply to Thread
Results 1 to 5 of 5

Detecting closure of a workbook

  1. #1
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Detecting closure of a workbook

    The Excel object model provides a Before_close event which apparently triggers directly after the close command is given. After this macro has run the option to save the workbook is offered if the saved property is set to false.

    I need to find a way of detecting the event AFTER the save dialog box has been processed or not shown at all. In other words, I want to detect when the workbook is actually about to close and do absolutely nothing else.

    Any ideas? Is there a way of generating an 'on_close' event?

    Thanks in advance

    Martin
    Martin

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Create an application level WorkBook_Deactivate routine that tests if the workbook is still there, if it isn't, it has just closed.
    Something like this untested routine in a class module, perhaps.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Interesting approach - thanks. I'll give it a try.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    The more I think about it, I prefer

    (pseudo-code)

    in a normal module
    Please Login or Register  to view this content.
    in a class module
    Please Login or Register  to view this content.
    If this code
    Please Login or Register  to view this content.
    is in the AppEvents code module, you will trigger for every workbook, or you could put the BeforeClose in ThisWorkbook code module for only those workbooks you wanted to trigger the alarm.
    Last edited by mikerickson; 11-28-2007 at 04:57 AM.

  5. #5
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Many thanks for your thoughts on this one.

+ 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