Close Workbook and Excel

DarbyBrown

New Member
Joined
Jan 22, 2016
Messages
31
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Are you getting any messages or alerts?
 
Upvote 0
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.
 
Upvote 0
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:
Upvote 0
Solution
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.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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