+ Reply to Thread
Results 1 to 5 of 5

Macro to close every Workbook in all Excel instances.

  1. #1
    Forum Contributor
    Join Date
    06-24-2013
    Location
    Berlin
    MS-Off Ver
    Excel 2007
    Posts
    188

    Macro to close every Workbook in all Excel instances.

    Hello Everyone,

    I wrote the following to close all workbook except the one associated to the running macro

    HTML Code: 
    It works fine, but I wonder how to close workbooks in other instances.

    would you know if this is possible?

    thanks for your time.

    -Philippe

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to close every Workbook in all Excel instances.

    Hi Philippe,

    Excellent question, even though it took 5 months to answer. See the attached sample file (with four 'data only' files) and code that follows that has the following capabilities:
    a. Count the number of open Excel Instances.
    b. Identify All Open Workbooks in All Open Instances of Excel.
    c. Close All Open Workbooks in All Open Instances of Excel except for the Workbook that is running the code. PERSONAL.xls or equivalent is closed in ALL Workbooks.
    d. Close PERSONAL.XLS or equivalent in the current instance of Excel without asking and without saving.
    e. Access the contents of an Excel File in another instance of Excel.

    Lewis

    Code follows in an Ordinary Code Module such as Module1:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    06-24-2013
    Location
    Berlin
    MS-Off Ver
    Excel 2007
    Posts
    188

    Re: Macro to close every Workbook in all Excel instances.

    Thanks LJMetzger. Now I need to debug through it step by step to understand it.

  4. #4
    Registered User
    Join Date
    02-02-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Macro to close every Workbook in all Excel instances.

    Hi

    I know this thread is old, but I'm hoping someone might be able to help.

    I'm getting a compile error, type mismatch at:

    Call IIDFromString(StrPtr(IID_IDispatch), iID)

    I'm running Office 365 Pro Plus OS 64bit, Excel 64bit. I've adapated the Private Declare statements at the beginning to be compatible with 64bit, ie "Private Declare PtrSafe Function" etc

    Any help greatly appreciated.

    Cheers

    pvr928

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to close every Workbook in all Excel instances.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

    ----------------------

    It is very difficult to debug a problem like yours out of context. If you still need a reply, start a new thread, that contains all the code (including API routine declarations) that will clearly demonstrate your problem.

    Lewis

+ 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. Excel to close all tabs and instances of IE
    By frank35 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-18-2013, 04:15 PM
  2. How to close hidden Excel instances?
    By bagullo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-17-2011, 06:39 AM
  3. Close Workbooks in Other Instances of Excel
    By c_leven3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2010, 10:47 AM
  4. How can I activate an open workbook by macro in seperate instances of Excel
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-15-2009, 12:05 AM
  5. Close all Instances of Excel
    By Tod in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2005, 01:06 PM

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