I am in Excel 2010 and I find that instead of working with custom events, there is a strange unexpected behavior .
I'm 99% sure that this approach worked for me a few years ago (maybe it was in Excel 03/07 - can not remember) Or <
Add a new class module and name it as
Start after public event () Private sub-square_inilize () Start after RaiseEvent End sub
Add another class module and name factoryist
Personal FactsFinanceFe Debug Set Tri as factory private sub-Clas_inishiali (in) cFactory = new factory and all private CFactory_AfterInitialize all () K Print "After initializing ..." and all
and a standard Module1
and run below
sub head () FTest = new factoryast and all
as the dim fTest factory entry I was expecting to see after this was started ..
in the immediate window But I do not ...
Through the Ste code it seems that private sub cFactory_AfterInitialize ()
never arrives ...
Note :
I can add a public subdivision Are: Start to raise ()
to the factory
class and then explicitly get started ()
event FactoryTest In
the cFactory.RaiseAfterInitialize ()
can be a possible work around but I'm actually trying to understand, so it does not work as shown above in the original way?
Does anyone tell me what I am doing?
In section VBA language specificity, I think the reason (emphasis is mine) is:
If a class defines class_inilize lifecycle handler, then each time when an instance of that class is created, substrate will be applied as a method by a new operator to a variable By referring to the
& lt; As-auto-object & gt;
and whose current value is nothing, or by calling the CreateObject function (Section 6.1.2.8.1.4) of the VBA standard library. The target object of the invitation is the newly created object Orientation is generated before the context of the newly created object, which is created from the operation. In your case, set
in the cfactory = new factory
Assignment is done
factory
before >> code of the class_Initialize method, which means that the event has been raised,factory access
> Method:It is not known about the example.
UPDATE
I have given a quick test by adding a method to this
factory
, which isClass_Initialize End sub
and then
FactoryTest.Class_Initialize
Start Private Sub-Classes () Set cFactory = new factory cFactory.test closing subSince the method
test
calls occurs afterN The
has been assigned to the cFactory
, "since the beginning ..." is required to be displayed message.
Comments
Post a Comment