+ Reply to Thread
Results 1 to 7 of 7

Check if workbook is the only Excel File Open

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Check if workbook is the only Excel File Open

    Hey all,

    I am just wondering if there is a way of checking if the workbook that is currently open is the only one that is open, as I have been asked to make my code exit the application if this is the case rather that just close that one file.

    Thanks.
    Last edited by duckboy1981; 07-20-2009 at 04:59 AM.
    Ducks are better crispy...

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Check if workbook is the only Excel File Open

    Hello duckboy1981,

    Are you referring to workbooks that are all open in the same instance of Excel or in separate instances of Excel or both?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Check if workbook is the only Excel File Open

    Hi

    You can check the Workbooks.Count property to see how many workbooks are currently open in your instance of Excel (and exit if more than 1). Note that this will include hidden workbooks as well (eg Personal.xls) which you may want to account for (g if 2 are open, then is one Personal.xls, if so don't close the wb).

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  4. #4
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Check if workbook is the only Excel File Open

    Hey Leith, thanks for the reply.

    Only workbooks in that instance, as any other instance shouldn't be affected by application.quit (I hope!)

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Check if workbook is the only Excel File Open

    Hello Duckboy,

    Have a look at Richard's answer.

  6. #6
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Check if workbook is the only Excel File Open

    Sorted, it was picking up 2 open workbooks even if only one, now I know why! Thanks.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Check if workbook is the only Excel File Open

    Hello duckboy1981,

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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