Save and closed excel workbook from the sheet

B

Bakar

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

Balka
 
B

Ben McClave

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
 
Top