Closed roxfr closed 4 years ago
Hi,
The Hook code should stop by itself. The MouseProc hook callback function checks (at each call) if the Userform window still exists by calling IsWindow(m_hWndForm).
What do you mean by "leaving the userform"? The code should stop if you unload or hide the form. But it doesn't work if your form is modeless.
Maybe share the code dealing with leaving the form (or more if you don't have privacy issues). Email me at cristian.buse@yahoo.com and I will respond quicker than here.
Good luck!
In the meanwhile a call to "UnHookMouse" function before leaving the form should work
I have looked into this further and apparently some people are experiencing a bug when using the 'Unload Form' method. This is completely unrelated with this project and it does indeed crash Excel. I've been able to replicate the issue as well. Try using a separate instance of your form ('Dim myForm As New frmWhatever' or 'With New frmWhatever ...') and use the .Hide command instead. The form will get out of scope and will eventually get removed from memory. Of course you need to make sure you do not have any external Object references in your form and that different instances of you form work as intended (some people code their forms with the goal of using just the global instance - which I found to be less desirable).
Hi, How to stop the code after leaving the userform, please. Because Excel freezes. Thank you. Cordially.