yes, there is a "global" event that you can use - and it appertains to the
Excel application.
Let's build it here:
so go to the development environment
to Personal.xls add a CLASS MODULE and name it XLclass
(menu Insert / Class Module)
place this code into the class module
Option Explicit
Public WithEvents xl As Excel.Application
Private Sub Class_Terminate()
Set xl = Nothing
End Sub
Private Sub Class_Initialize()
Set xl = Excel.Application
End Sub
Private Sub xl_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Saving " & Wb.Name
End Sub
we need to add some code to initialise this object, so add a standard code
module (Insert/Module) and add this code:
Option Explicit
Public xl As xlClass
Sub InvokeXL()
Set xl = New xlClass
End Sub
and now we need to run this as soon as Personal.xls opens, so we'll use the
workbook's open event to do this.
Go to the code page for ThisWorkbook (in the personal.xls project) and add
this code:
Private Sub Workbook_Open()
InvokeXL
End Sub
How does it hang together?
When the workbook is opened, the open event call InvokeXL.
InvokeXL creates the xlclass object and by doing to, the object, as its
global, is now ready and running. whenever a workbook is saved, the
application level WorkbookBeforeSave event fires, and you'll get the message
for which workbook is being saved. Thats just for demo ...but you know that
the workbook object, WB refers to that particular workbook.
You can add code like
WB.Worksheets("main").Range("A1")=format$(Date,"dd-mmm-yyyy")
using the application class is a nice "tool" for this kind of trapping -
though I've not often seen it used in business. shame