cristianbuse / VBA-UserForm-MouseScroll

Use the Mouse Scroll Wheel to scroll VBA UserForms and Controls
MIT License
70 stars 12 forks source link

Stop the code #1

Closed roxfr closed 4 years ago

roxfr commented 4 years ago

Hi, How to stop the code after leaving the userform, please. Because Excel freezes. Thank you. Cordially.

cristianbuse commented 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!

cristianbuse commented 4 years ago

In the meanwhile a call to "UnHookMouse" function before leaving the form should work

cristianbuse commented 4 years ago

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).