+ Reply to Thread
Results 1 to 20 of 20

Close all other applications

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Close all other applications

    Hi All

    I want to write vba code that is invoked on opening a spreadsheet that will firstly warn the user that if they continue(vb yes/No) then all open MS office applications will be automatically closed (Like MS Outlook,MSWOrd, Power point etc) .

    So the vba code should close all Microsoft applications except the current spreadsheet.

    Any help would be much appreciated.

    Thanks
    Last edited by aman1234; 08-08-2011 at 06:35 AM.

  2. #2
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Close all other applications

    Try this for word, outlook and power point:
    Please Login or Register  to view this content.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Close all other applications

    A little tighter implementation, just list the apps you want to close in the array at the top:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    Hi guys

    Thanks a lot for your help. It worked but just one question "Is it possible if other excel applications are opened then close them too apart from this current workbook"

    Please see attached.

    Thanks
    Attached Files Attached Files

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Close all other applications

    I would suggest you correct your system settings so that all Excel workbooks are opened in the same instance of Excel. Allowing the system to start multiple instances of the same App usually gives me more grief than benefit.

    Then you won't need to hunt for other "instances" of Excel, they won't exist.

  6. #6
    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: Close all other applications

    Hello aman1234,

    There is no need to correct anything. This can be easily accomplished using the Windows API. Copy this code into a separate module in your workbook's VBA project. You can call the macro manually, using ALT+F8, or call from inside your code. This closes only Office applications other than the one running the macro.
    Please Login or Register  to view this content.
    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!)

  7. #7
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    Hi Leith

    I have written the following code but it doesn't do anything:

    Please Login or Register  to view this content.
    I hope you can help me out in this.

    Thanks

  8. #8
    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: Close all other applications

    Hello aman1234,

    If nothing happened then you have no Office applications running besides Excel. This macro will not close other workbooks that are open in the same instance of Excel. Perhaps I misunderstood your needs. If you need to close all other workbooks, except the one running the macro, in the same instance of excel then you will need the macro below,
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    Hi guys

    The code was working but suppose if already opened applications are not saved yet then this code asks everytime "do you want to save the application first before closing" . I want it to automatically save all the opened applications before closing.

    Can anyone please help me how to do it?

    Thanks
    Attached Files Attached Files

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Close all other applications

    To me it seems your project is heading for 'the most irritation provoking software' award.



  11. #11
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    Well snb. I am not hear to get any award . If you can't help to solve my problem then please don't comment atleast.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Close all other applications

    Add this to autosave changes:
    Please Login or Register  to view this content.

    SNB's comment was meant to warn you again that others using your macros might not appreciate these decisions.

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Close all other applications

    @JB

    How very correct indeed !

  14. #14
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    Hi
    The following code will only save the workbooks but I want to save all the applications which are currently opened automatically before closing them e.g access, word , powerpoint applications.
    Please Login or Register  to view this content.
    Thanks
    Last edited by aman1234; 08-30-2011 at 07:35 AM.

  15. #15
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Close all other applications

    @Amman

    Since 24-02-2009 you started 137 threads, of which 12 you marked as 'solved'. Are those 125 threads still bothering you ?
    If not, please mark them as 'solved', or send a moderator a request to do so.

  16. #16
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    You have time to view my thread again and again but no knowledge to solve my problem.
    Marking other threads solved is not the answer of my question in this thread.

  17. #17
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Close all other applications

    @aman

    Why does your Excel workbook need to close every other Office application?
    Hope that helps,

    Colin

    RAD Excel Blog

  18. #18
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Close all other applications

    Proper forum behaviour will be highly appreciated ! (see the forum rules)
    Especially in return of so much outstanding free help.

  19. #19
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close all other applications

    Hi Colin

    This is what my boss asked me to do. So I am able to close all the office a[pplications but not sure how to save them automatically before closing them.

    Thanks

  20. #20
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Close all other applications

    Hi Aman,

    I feel your pain.

    The reason I asked is I couldn't think of a genuinely good reason to require that all other Office applications be closed down when a workbook is opened. Perhaps you should ask your boss to clarify why s/he asked for this, because at the moment it sounds like a very questionable design decision. Nobody (except your boss?) wants a workbook to close down all of their open Office apps.

    Once we understand the reason(s) why, we may be able to think of a better solution for you.

    My 2 cents...

+ 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