+ Reply to Thread
Results 1 to 4 of 4

Checking if a workbook is already open and closing it

  1. #1
    Registered User
    Join Date
    06-01-2013
    Location
    NJ
    MS-Off Ver
    Excel 2004
    Posts
    2

    Checking if a workbook is already open and closing it

    Hello Excel and VBA gurus. I've been having a hard time solving this problem. Its probably a very simple solution and you're gonna laugh at me, but its just that i have a lack of knowledge of the various 'workbook' functions and how they act and such... "this", "active", opening, when to use a path, when to use the name of the file, etc... Anyway, here is the rundown:

    I have Two files: "ICE1.xls" and "Standards.xls". The file location of "ICE1.xls" varies and hopefully isnt vital to solving this problem. The file location of "standards.xls" is "c:\Standards.xls".

    The gist of whats going on:

    I open ICE1 manually. I start the macro. It does some fancy things in ICE1. Then it opens STANDARDS, copies some things, closes STANDARDS, and goes back into ICE1 and pastes the data. I made the macro and everything works well if STANDARDS is CLOSED when i start the macro. However, if STANDARDS is open when i start the macro, it gives me a popup saying that its open, everything goes crazy and all hell breaks loose.

    What i would like to do:

    Run macro. Determine if STANDARDS is open. If it is open -> Close it and then go back to the program where it can Re-open STANDARDS (or maybe i should go to it right off the bat if that is simpler?), do some fancy things, close STANDARDS, and then put that data into ICE1.

    OR

    Run Macro. Determine if STANDARDS is open. If its NOT OPEN-> open it, do some fancy things, close standards, and put the data into ICE1.

    I'm having trouble determining if its open, and where to go from there in order to be sure that ICE1 will be the activated workbook after i have closed STANDARDS.

    Sorry if something doesn't make sense. I'm not good with words.
    Thank you!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,142

    Re: Checking if a workbook is already open and closing it

    Untested, but try:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-01-2013
    Location
    NJ
    MS-Off Ver
    Excel 2004
    Posts
    2

    Re: Checking if a workbook is already open and closing it

    Thank you for that! The " ON ERROR RESUME NEXT" thing was helpful. I tried your code but something was still glitchy, which was probably my fault. I tried something simpler and got rid of the IF statement:

    Please Login or Register  to view this content.
    It works. Huzzah.
    i knew it wasn't going to be complicated. Needed a fresh start.
    Thank you for the help.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,142

    Re: Checking if a workbook is already open and closing it

    You're welcome. Thanks for the rep.

    I'm not quite sure how the revised code is working for you but, if it works, no problem.


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


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    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


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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