+ Reply to Thread
Results 1 to 5 of 5

How can I completely close a specific workbook without closing other open workbooks

  1. #1
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Question How can I completely close a specific workbook without closing other open workbooks

    Good evening,

    I'm having some handling the closing of a workbook in VBA from a userform. The userform is displayed to the user whenever the workbook opens.

    PROBLEM:
    To put it simply, when I use:

    Please Login or Register  to view this content.
    the workbook closes as expected. However, when I open that workbook it's as if it hasn't closed completely as the workbook open event doesn't fire.

    I checked the active processors and it seems that the instance of the Excel application is still running as a background process.

    If I use:

    Please Login or Register  to view this content.
    This does complete close the workbook, however, all opened workbooks are also closed, so this isn't really an option unless I want irate users banging down my door complaining about losing their work

    Thanks in advance.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: How can I completely close a specific workbook without closing other open workbooks

    Is the active workbook you're trying to close the one that the userform is being run from?

    Perhaps a sample workbook would make things clearer.

    BSB

  3. #3
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: How can I completely close a specific workbook without closing other open workbooks

    Thanks for your reply.

    Is the active workbook you're trying to close the one that the userform is being run from?
    Yes.

    Not a problem. I have attached it.

    Here is what you need to do to reproduce the problem.
    1. Open Book1.xlsm
    2. Click the close button on the userform
    3. A message box will offer a yes/no response. Click Yes to close the workbook.
    4. Don't close the black excel window. Instead, open Book1.xlsm again. You should now see the problem - the workbook open event doesn't fire and the userform isn't displayed.

    Cheers!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: How can I completely close a specific workbook without closing other open workbooks

    When opening the workbook for the second time (without closing the Excel Application), the problem seems to be caused by the use of the Application.EnableEvents property:

    Please Login or Register  to view this content.
    If I remove that statement (Application.EnableEvents), the workbook open event fires and the userform is displayed.

    Obviously this isn't a problem when opening the workbook for the first time.

    #Confusing
    Last edited by Sc0ut; 02-07-2016 at 08:12 AM.

  5. #5
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Re: How can I completely close a specific workbook without closing other open workbooks

    Moved to a new thread.

+ 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 close and re-open a workbook at specific time
    By hasanqz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2015, 03:38 PM
  2. Replies: 0
    Last Post: 08-07-2014, 06:56 PM
  3. [SOLVED] Closing a Workbook from another workbook: Workbooks.close error: Subscript out of range
    By Coreyusa in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-14-2013, 06:45 PM
  4. [SOLVED] Open Multiple Workbooks, Record names, Copy paste to Active Workbook, Close the Workbooks
    By vba_madness in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2013, 06:09 AM
  5. [SOLVED] Edit code to close all workbooks except active workbook and other specific workbook
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2012, 09:29 PM
  6. close workbooks without closing excel ?
    By Clute in forum Excel General
    Replies: 2
    Last Post: 08-05-2006, 04:50 PM
  7. How to close specific workbook not all active workbooks?
    By Bon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2006, 10:55 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