Click on "Close" and it saves & closes. How to do it?

M

Marvin Hlavac

I'd like to be able to just click on Close and the workbook would be saved
and closed without the "Dou You Want to Save, Yes or No" dialog.

Thanks in advance.
 
V

Vasant Nanavati

Put the following into the ThisWorkbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Name <> FullName Then
Save
Close
End If
End Sub

Note that if you have any BeforeSave or BeforeClose code, it may interfere
with this macro unless appropriately handled.
 
M

Marvin Hlavac

Thanks Vasant,

As always the code you supplied works exactly as intended. I only hope that
one day I will know at least 5% of what you do :)

--
Regards,
Marvin Hlavac
Toronto, Canada
 
V

Vasant Nanavati

Just stick around the newsgroups and before you know it, you'll be an
expert! That's how many of us learned most of what we know.
 

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