Application Quit issue

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
428
Office Version
  1. 365
Platform
  1. Windows
I have the sub below called from a button for a workbook called 'Events' and when the button is clicked the workbook is saved, this all works fine up to this point.

What I want it to do is check if there any other non related workbooks currently open and it there wasn't for it to close the 'Events' workbook and quit Excel completely and if there were other non related workbooks open to just close the 'Events' workbook and and any others would remain open by just using
VBA Code:
 ActiveWorkbook.Close SaveChanges:=True
.

The issue I'm having is whilst testing this sub when its the only workbook open it just closes thr workbook Not the workbook and Excel.
I'm sure its something to do with perhaps the order I have the code in but even after changing it around it still won't work.

Anyone got any suggestions on whats wrong and how to resolve it?

Thanks Paul

VBA Code:
Sub ExitWB()
Dim wbCount As Integer

    ActiveWorkbook.Close SaveChanges:=True
   
    wbCount = Workbooks.Count - 1

    If wbCount = 0 Then
   
        Application.Quit
       
    End If

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Maybe
VBA Code:
Sub ExitWB()
    ActiveWorkbook.Save
    If Application.Workbooks.Count = 1 Then Application.Quit Else ActiveWorkbook.Close
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top