I used this example from Bob Phillips to realise it...thx Bob! Code
explanation in help does not explain it this clearly.
Bob Phillips
Re: Using Events with the Application Object & XL 2003
------------------------------------------------------------------------
From your response, I get the impression that I need to ""Dim X as a New
EvenClassModule" and the Sub InitializeApp()". I am testing that statement
to see whether you agree or not. If I don't do that, then what
happens?
Without this, nothing happens, because as Chip says, all you have is
an
object template, you will not have created an instance of that oject.
For example, let's say I don't "instantiate" the class module, will Create
a Private Sub App_WorkbookOpen(ByVal Wb As Workbook)" still function?
CanI still set my global variable?
If you don't Dim X, this statement will error.
This goes in the normal (non-class) module, correct? What calls "Sub
InitializeApp()"?
I tend to do it in a normal workbook_Open event for that workbook. This
is
my example post on App Events.
Firstly, all of this code goes in the designated workbook.
'========================================
Insert a class module, rename it to
'clsAppEvents', with this codeOption Explicit
Public WithEvents App As Application
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
msgbox Wb.Name
End Sub
'========================================In ThisWorkbook code module,
add this event code
Dim AppClass As New clsAppEvents
Private Sub Workbook_Open()
Set AppClass.App = Application
End Sub
Either save the workbook, close it and re-open it to initaite
application
events, or just run the Workbook_Open code manually. From then on,
each
workbook opened will display the name.