+ Reply to Thread
Results 1 to 7 of 7

Macro to close all workbooks except active workbook and one other named workbook

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Macro to close all workbooks except active workbook and one other named workbook

    Hello,

    I have this code that closes all workbooks, except the active one.

    Sub Close_Non_Active_Workbooks()

    Dim WB As Workbook

    For Each WB In Workbooks
    If Not (WB Is ActiveWorkbook) Then WB.Close
    Next

    End Sub


    I have a file called "My Macros" that I have open to run quite a few reports, so I would like to adjust the above code.
    I would like a code that will close all workbooks except the active one and the workbook called "My Macros"

    Any help would be appreciated.

    Jonathan.

  2. #2
    Registered User
    Join Date
    09-10-2014
    Location
    Matrix
    MS-Off Ver
    2010
    Posts
    70

    Re: Macro to close all workbooks except active workbook and one other named workbook

    Please Login or Register  to view this content.
    (*) Reputation points appreciated.
    excelbs.tk

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to close all workbooks except active workbook and one other named workbook

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to close all workbooks except active workbook and one other named workbook

    You did not tell us which workbook contains the macro below.
    If it is contained in My Macros and run from a different workbook, this works:
    Please Login or Register  to view this content.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Macro to close all workbooks except active workbook and one other named workbook

    Thank you michson,

    Your code was exactly what I needed.

  6. #6
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Macro to close all workbooks except active workbook and one other named workbook

    Hello kev,

    Your interpretation was correct, the macro was in the file called "My Macros".
    Your code did exactly what I needed.

    Thank you

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to close all workbooks except active workbook and one other named workbook

    Did you try my code? What happened?

+ 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. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 AM
  2. [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
  3. VBA macro for hyperlink to active workbook in the active workbook path
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-10-2013, 05:37 AM
  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. Replies: 2
    Last Post: 06-20-2012, 09:08 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

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