+ Reply to Thread
Results 1 to 2 of 2

Workbook_BeforeClose event fires twice when Excel itself is closing

  1. #1
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Workbook_BeforeClose event fires twice when Excel itself is closing

    Hi folks, hoping someone can help me with this.

    I have a workbook with a _BeforeClose event which fires twice, but only when the Excel application itself is closing. When the event fires the second time, the workbook is already "gone" from Excel and the objects it is referencing do not exist, leading to a runtime error.

    When I close the workbook WITHOUT closing Excel, everything functions as expected.

    As you can see, the Workbook_Close event and the doShutDown() function below both make calls to routines in other code modules. I have not supplied these here as there are a few. I have however tried removing these calls, but doing so does not fix the 'double-firing' behaviour so I think these can be safely eliminated from suspicion.

    Please Login or Register  to view this content.
    Last edited by blackworx; 07-19-2012 at 05:18 AM.

  2. #2
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Workbook_BeforeClose event fires twice when Excel itself is closing

    Panic over.

    I managed to trace the problem to a combobox object on one of the worksheets, whose _Change event was for some reason firing after the workbook closed. I'm thinking it was possibly queued up for action while the Workbook_BeforeClose event was running? If so that doesn't explain why it only happened when Excel was closing.

    Adding an Application.EnableEvents = False statement did not however fix it. I had to trap the error within the combobox_Change event and just force it to fail silently.

    Curious.

    Apologies (and thank you) to anyone who was already in the middle of writing a reply when I posted this!

+ 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