Subclassing in Excel ! ...So frustrating !
Maybe the Help topic "Understanding the Lifetime of Variables" will clarify
some of these points:
"A module-level variable differs from a static variable. In a standard
module or a class module, it retains its value until you stop running your
code."
(I haven't personally worked with callback procedures and DLL calls, etc.,
but just happened to see this topic while browsing and thought this might be
one idea that might lead to the source of the problem.)
For example, build the following trivial standard module and test the
following code:
==========
Option Explicit
Dim lngTest As Long 'Module-level variable
Public Sub Test()
lngTest = 1
End Sub
==========
Single-step through Sub Test with the Locals window open. Notice that the
value of lngTest is available (and valid) only while Sub Test is running.
Double-check this by entering the command "?lngTest" in the Immediate
window. Now after Sub Test is finished, enter the command "?lngTest" in the
Immediate window again. Notice that the value is now blank (VBA has cleared
it!).
Doesn't the same thing happen to the value of OldWindowProc in your Sub
SubClass as soon as it is finished running the first (and only) time?
Function NewWindowProc won't get called until the mouse moves, so therefore,
won't the value of OldWindowProc be out of scope from the time that Sub
SubClass ends and the time that the next mouse event occurs? What happens if
you insert a Debug.Print OldWindowProc in Function NewWindowProc and watch
it in the Immediate window while the code runs?
--
HTH,
Bill
"RAFAAJ2000" wrote in message
...
Thanks Bill,
I am not sure I understand what you mean but none of the variables go out
of
scope as they are all declared at a module level.
Any other ideas ?
Regards.
|