ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro each time a workbook is saved (https://www.excelbanter.com/excel-programming/310087-run-macro-each-time-workbook-saved.html)

donbuz

Run a macro each time a workbook is saved
 
Hi everybody,
I would like to know how to run a macro any time a workbook is bein
saved. I created my macro is saved in "Personal.xls" but I do not kno
how to trigger it without using a button associated to it but instea
when the user would click File-save or directly the save icon. I trie
to add a call to my macro in the code of the event BeforeSave o
"Personal.xls" but it does not work...

Thanks to whoever can give me a hand on this.

donbu

--
Message posted from http://www.ExcelForum.com


DH[_2_]

Run a macro each time a workbook is saved
 
You will need to create class event to trap the event of any open workbook
being saved.
The class event can reside in your personal.zls.

A good resource to read up on this is in chip pearson web site.
url I think is www.cpearson.com

as well do a googgle search on class events.

to get you started.....
Put the following in a new class module
' use insert class module from vbe

rename it to EventClass

Option Explicit
Public WithEvents App As Application

Private Sub App_WorkbookBeforeSave(ByVal wb As Workbook, Cancel As Boolean)
' your code
end sub


In this thisworkbook module of personal.xls
Option Explicit
Dim AppClass As EventClass

Private Sub Workbook_Open()
Set AppClass = New EventClass
Set AppClass.App = Application
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set AppClass.App = Nothing
End Sub


"donbuz " wrote in message
...
Hi everybody,
I would like to know how to run a macro any time a workbook is being
saved. I created my macro is saved in "Personal.xls" but I do not know
how to trigger it without using a button associated to it but instead
when the user would click File-save or directly the save icon. I tried
to add a call to my macro in the code of the event BeforeSave of
"Personal.xls" but it does not work...

Thanks to whoever can give me a hand on this.

donbuz


---
Message posted from http://www.ExcelForum.com/




donbuz[_2_]

Run a macro each time a workbook is saved
 
Great answer quick & accurate, thx a lo

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 03:30 PM.

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