Close command button

pujo

Well-known Member
Joined
Feb 19, 2009
Messages
708
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hey all,
Trying to make a command button that saves the workbook and then closes.
I have this code and it works somewhat. I want to save and close without the save dialog popping up asking is I want to save the changes, as the workbook has already been saved in the macro. Is there a way around this?
Thanks,
Pujo
Code:
Private Sub CommandButton2_Click()
ActiveWorkbook.Save
Application.Quit
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I would have thought that would work but perhaps

Code:
Private Sub CommandButton2_Click()
ActiveWorkbook.Save
ActiveWorkbook.Saved = True
Application.Quit
End Sub
 
Upvote 0
Still asking if I want to save changes¿
Don't understand, it should save and close without the prompt?
Code:
Private Sub CommandButton2_Click()
ActiveWorkbook.Save
ActiveWorkbook.Saved = True
Application.Quit
End Sub</pre>
 
Upvote 0
Sledgehammer approach :)

Code:
Private Sub CommandButton2_Click()
ActiveWorkbook.Save
ActiveWorkbook.Saved = True
Application.DisplayAlerts = False
Application.Quit
End Sub
 
Upvote 0
Brute Force always works.:ROFLMAO:
Thanks!

Have a good weekend.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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