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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top