Autorun a macro on save

U

Udo

Hi Excelperts,

there are several macros I created that run automatically when the
workbook is opened. I have also some on closing the workbook. But I
couldn't figure out yet how to make a macro run when the file is
saved. To be very specific: if you close the file without saving, it
should not run, only when the file is saved. This is when you close
and save in one step or when you save it and continue to work on it.
I've tried workbook_save, on_save, auto_save. but it didn't work out.
So, any hint how to do it?

Thanks in advance
hamster
 
R

ryguy7272

I do it like this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call '...you macro here
End Sub

Those three lines fo code go into 'ThisWorkbook' sheet.

HTH,
Ryan---
 

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