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:

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,562
You can't shut down only one worksheet but you can hide it so it's not visible.
 

alexdurc09

New Member
Joined
Sep 21, 2018
Messages
17
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?
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,562
You can't close down the sheet, you can only hide it from view.
Code:
ActiveSheet.Visible = False
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,340
Office Version
  1. 365
Platform
  1. Windows
If you just want to save & close the workbook containing the code try
Code:
Private Sub SaveClose_Click()
ThisWorkbook.Close True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,011
Messages
5,526,263
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top