Only closing active sheet Code Mod

alexdurc09

New Member
Joined
Sep 21, 2018
Messages
17
Hello,
I have the below code which is attached to a button on aspreadsheet. Its function is to close the spreadsheet down and also savechanges. However, when the button is clicked, it closes down all open spread sheetswhich is no good if my colleagues are working other spread sheets too. Is thereany way so that when clicked, it just shuts down the active spreadsheet and notany other open spread sheets?
TIA,
Alex

Private Sub SaveClose_Click()
ThisWorkbook.allowed = True
Application.Quit
ThisWorkbook.Save
End Sub
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You can't shut down only one worksheet but you can hide it so it's not visible.
 
Upvote 0
So to clarify, there isn't any VBA code which will close down the sheet that the button is on and were the vba is written and leave all other sheets open?
 
Upvote 0
You can't close down the sheet, you can only hide it from view.
Code:
ActiveSheet.Visible = False
 
Upvote 0
If you just want to save & close the workbook containing the code try
Code:
Private Sub SaveClose_Click()
ThisWorkbook.Close True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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