+ Reply to Thread
Results 1 to 4 of 4

Workbook_BeforeClose Event Procedure

  1. #1
    Registered User
    Join Date
    02-18-2009
    Location
    Apex, NC, USA
    MS-Off Ver
    Office 365
    Posts
    64

    Question Workbook_BeforeClose Event Procedure

    I have written an event procedure that is intended to prevent Excel from asking whether the user wants the Personal workbook to be saved. The macros that are called in the Personal WB's auto-open macro store intermediate results in the Personal WB worksheets so that Excel always finds changes have been made and therefore asks the user if it is to be saved before closing. However the stored results are just that...intermediate....and not needed. The Personal workbook never needs to be saved by the user. I want to prevent Excel from bothering the user in this case.

    I found in my Excel 2003 VBA Programmers Reference (Paul T. Kimmel, etal.) the following event procedure:

    Please Login or Register  to view this content.
    The code is placed in the ThisWorkbook module of the Personal WB.

    However, it is not working all the time. I believe it is not working because it is not invoked under certain "closing circumstances". I suspect this because I have placed a breakpoint at the line:

    Please Login or Register  to view this content.

    It seems to work when I explicitly do a File-->Close command against the Personal WB. It works, and as anticipated it hits the breakpoint. When directed to continue the command works and the WB is closed with no further ado!

    However if I just click the Windows close (X) button for the window, the event procedure seems not to run. Excel proceeds to ask if the application workbook is to be saved (which I expect), but then proceeds to do the same for the Personal WB. The breakpoint is not hit, and the Excel dialog asking the user whether to save the Personal workbook is (undesirably) displayed.

    The Personal WB runs as hidden and no one is going to do an explicit File-> Close of the WB. They will always just click the Window's X. ....leaving me where I started.

    Is this a limitation of the event procedure design? It seems Windows does return control to Excel because Excel properly asks the user about saving the Application WB. However, my environment is behaving as if Excel doesn't invoke the Workbook_BeforeClose event procedure.

    Other facts: Vista, Excel 2010


    Any help would be appreciated.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Workbook_BeforeClose Event Procedure

    If you have a macro in your personal.xlsb that is storing data IN that file, edit THAT macro to save the personal file during that macro rather than in a separate event.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-18-2009
    Location
    Apex, NC, USA
    MS-Off Ver
    Office 365
    Posts
    64

    Re: Workbook_BeforeClose Event Procedure

    Thanks for the quick and thoughtful reply. It's the "keep it simple" thought. Your thought generated a thought of mine too: I don't need to incur the overhead of doing a save at all. I can still just do the

    Please Login or Register  to view this content.

    at the point I store into the workbook. ... because, it wasn't that the

    ThisWorkbook.Save = True

    didn't work, it was was that it wasn't getting executed.

    Thanks again.
    Last edited by DanBlum; 04-20-2012 at 07:56 AM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Workbook_BeforeClose Event Procedure

    If that takes care of your need, please click Thread Tools above your first post and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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