Auto-save on close

S

SthOzNewbie

In Excel 2000 is it possible to imbed some code in a worksheet that will
automatically save the file when it is closed (rather than go through the
"are you sure...." routine). The standard autosave add-in is already being
used but the user wants to be able to close the sheet and not be prompted -
just have the file saved as default.

TIA

IK
 
M

Muhammed Rafeek M

Hi
u can use this code.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub
 
S

SthOzNewbie

Thanks for the quick reply.

I saved this code into a module in a workbook but was still prompted with
the "Do you want to save changes..." dialogue when I closed the workbook.
I have not worked with code much so I have probably done something very
basically wrong.

Regards,

Ilya
 
N

NickHK

You need to add a line:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
Cancel=True
End Sub

NickHK
 
S

SthOzNewbie

Thank you. I added the line but am still getting the message box coming up.

This is probably a really dumb question but should I be inserting the actual
name of the workbook somewhere ?

Have I put the code in the right place ? (It's in Module1 of the workbook)

Regards,

IK
 
N

NickHK

No, it is a workbook events "Workbook_BeforeClose", so it needs to go on the
ThisWorkBook module.
Sorry, delete the "Cancel=True", thought we were in the _BeforeSave event

NickHK
 
S

SthOzNewbie

Excellent, that's done the trick

Cheers,

IK

NickHK said:
No, it is a workbook events "Workbook_BeforeClose", so it needs to go on the
ThisWorkBook module.
Sorry, delete the "Cancel=True", thought we were in the _BeforeSave event

NickHK
 
D

Dave Peterson

Don't do this.

You're gonna be upset when you make a disastrous error -- deleting data or
changing code -- and then want to close without saving.

If you do do it, make sure you keep plenty of backups.
 
C

Curt

Hope I understand you with cancel=true close happens without saving changes
correct if so no reply needed
thanks
 

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