Close Workbook and Excel

DarbyBrown

New Member
Joined
Jan 22, 2016
Messages
29
I have a macro that is supposed to Close the open Workbook, and shutdown Excel. It closes the Workbook OK, but does not shutdown Excel.

The code is below, what is wrong?

I am running Excel 2010, on Windows 10 Pro.

Code for Savit

Sub Savit()
'
' Savit Macro
' Saves and closes the workbook
'
' Keyboard Shortcut: Ctrl+s
'
Application.DisplayAlerts = False
With ThisWorkbook
.Save
.Close
End With
Application.DisplayAlerts = True
Application.Quit
End Sub
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Are you getting any messages or alerts?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,882
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

If you close the workbook, it cannot get to the lines of code after that!
So just remove the:
Code:
.Close
line, and it will work the way you want.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,882
Office Version
  1. 365
Platform
  1. Windows
See my reply above.
By closing it before quitting, you are essentially terminating the code running at that point (if the workbook has been closed, it cannot continue to run any code posted below that line!).
Quitting Excel will also close the workbook, so you do not need an explicit command for that.
 
Last edited:
Solution

DarbyBrown

New Member
Joined
Jan 22, 2016
Messages
29
Welcome to the Board!

If you close the workbook, it cannot get to the lines of code after that!
So just remove the:
Code:
.Close
line, and it will work the way you want.

Thank You, how simple. Looking me right in the face and still couldn't see it.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,767
Members
413,933
Latest member
Msar5586

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
Top