+ Reply to Thread
Results 1 to 4 of 4

Close application if last workbook is closed

Hybrid View

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Close application if last workbook is closed

    Hi Again! :-)


    I found a bit of code that closes the application when also closing a workbook. Problem is if I have several workbooks open they all close with a prompt to save those who are unsaved.
    Then I have to reopen the ones I need.

    If I close all workbooks manually the application is still active greyed out in menus and so on.

    Is there any way to use vba to check if the workbook I'm closing is the last one open?

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

    Re: Close application if last workbook is closed

    Don't know what code you have but perhaps you could fit this in somewhere.
    If Workbooks.Count = 1 Then
        Workbooks(1).Close
        Application.Quit
    End If
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Close application if last workbook is closed

    Might be useful.
    Will try some later today.
    Thanks

  4. #4
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Close application if last workbook is closed

    Ok, was able to use your suggestion Norie

    It works as I want to as this:
    Sub ClsNQt()
    If Workbooks.Count = 1 Then
    Application.Quit
    Else
    Workbooks(1).Close
    End If
    End Sub
    Last edited by Rob*; 11-29-2012 at 02:57 AM.

+ 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