ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save and closed excel workbook from the sheet (https://www.excelbanter.com/excel-programming/447529-save-closed-excel-workbook-sheet.html)

Bakar

Save and closed excel workbook from the sheet
 
Hi Masters
I want to have a command button which is located on my excel sheet
so that i click on it it save my document and close the workbook also

Plz help

Balkar

Ben McClave

Save and closed excel workbook from the sheet
 
Hi Bakar,

This code should work:


Sub SaveAndClose()

If MsgBox("Would you like to save this workbook and close it?", vbYesNoCancel, "Save and Close?") < vbYes _
Then Exit Sub

With ActiveWorkbook
If .Path = "" Then
.SaveAs
Else
.Save
.Close
End If
End With

End Sub


All times are GMT +1. The time now is 11:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com