ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autorun a macro on save (https://www.excelbanter.com/excel-programming/426430-autorun-macro-save.html)

Udo

Autorun a macro on save
 
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

ryguy7272

Autorun a macro on save
 
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---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Udo" wrote:

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



All times are GMT +1. The time now is 10:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com