View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
DH[_2_] DH[_2_] is offline
external usenet poster
 
Posts: 5
Default 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/