+ Reply to Thread
Results 1 to 16 of 16

Code closes all but active workbook, also closes personal...

  1. #1
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Code closes all but active workbook, also closes personal...

    Have code that closes all but active workbook (see below), but also closes the hidden personal.xlsb file. Hoping there's a simple addition to not close the personal file?

    Please Login or Register  to view this content.
    Many thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Code closes all but active workbook, also closes personal...

    Modify the logic to check if the workbook name through iteration is not your personal.xlsb workbook as well.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: Code closes all but active workbook, also closes personal...

    A thing of beauty... many thanks!!

  4. #4
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Code closes all but active workbook, also closes personal...

    Quote Originally Posted by fourmurphys View Post
    A thing of beauty... many thanks!!
    You're welcome

  5. #5
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: Code closes all but active workbook, also closes personal...

    well.... i'm sorry... spoke too soon... it's still closing the personal.xlsb file... I tried changing AND to OR and same result... also confirmed file name... thoughts?

  6. #6
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Code closes all but active workbook, also closes personal...

    Quote Originally Posted by fourmurphys View Post
    well.... i'm sorry... spoke too soon... it's still closing the personal.xlsb file... I tried changing AND to OR and same result... also confirmed file name... thoughts?
    How about

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: Code closes all but active workbook, also closes personal...

    hmmm... no dice... I'll keep searching as well... thanks for trying!

  8. #8
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Code closes all but active workbook, also closes personal...

    Humor me what happens if you run this.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: Code closes all but active workbook, also closes personal...

    The first and only message box: "Closing PERSONAL.XLSB"
    :|

  10. #10
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373
    Quote Originally Posted by fourmurphys View Post
    The first and only message box: "Closing PERSONAL.XLSB"
    :|
    Oh ok, change the code to <> PERSONAL.XLSB

    VBA is case sensitive.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code closes all but active workbook, also closes personal...

    What are you actually trying to do?

    Why do you want to close all workbooks bar the active and personal ones?

    By the way, which workbook is the code in?
    If posting code please use code tags, see here.

  12. #12
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: Code closes all but active workbook, also closes personal...

    Norie, I have code that opens several variably-named workbooks, and would like to close them all except my main workbook at the end of the code. But I want to leave the personal file open because that's where the module and macros are.

    Poizhan, it worked! Didn't know VBA was case-sensitive... I went back to your second option above and finished with this:

    Please Login or Register  to view this content.
    Again, and this time for real, it works! Thanks!!

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Code closes all but active workbook, also closes personal...

    Perhaps
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  14. #14
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Code closes all but active workbook, also closes personal...

    Quote Originally Posted by fourmurphys View Post
    Norie, I have code that opens several variably-named workbooks, and would like to close them all except my main workbook at the end of the code. But I want to leave the personal file open because that's where the module and macros are.

    Poizhan, it worked! Didn't know VBA was case-sensitive... I went back to your second option above and finished with this:

    Please Login or Register  to view this content.
    Again, and this time for real, it works! Thanks!!
    Welcome

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code closes all but active workbook, also closes personal...

    Why not close the workbook(s) you are opening once you've 'finished' with them?

    Wouldn't that be a better idea?

  16. #16
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: Code closes all but active workbook, also closes personal...

    well.... yes it would... come to think of it...

    but this was more fun, and I learned some new tricks, so that's a plus!


+ 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] Workbook automaticly closes
    By erich_7719 in forum Excel General
    Replies: 4
    Last Post: 08-13-2016, 11:21 PM
  2. [SOLVED] VBA code closes application and not individual workbook
    By brharrii in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2013, 04:17 PM
  3. Replies: 0
    Last Post: 07-02-2013, 01:20 PM
  4. [SOLVED] Esc Key Closes Workbook
    By MSweetG222 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2006, 07:00 PM
  5. [SOLVED] run a macro before a workbook closes
    By Jonathan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-17-2005, 12:10 PM
  6. going to hyperlink closes workbook
    By billb in forum Excel General
    Replies: 1
    Last Post: 11-16-2005, 07:15 PM
  7. Code only closes the worksheet; why???
    By EMoe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2005, 10:52 PM

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