cristianbuse / VBA-UserForm-MouseScroll

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

Variable not defined #16

Closed piotrpoletek closed 2 years ago

piotrpoletek commented 2 years ago

Hi,

I'm trying to use the code in my form, but I get Variable not defined error for MouseOverControl in For Each frmCtrl In uForm.Controls subControls.Add MouseOverControl.CreateFromControl(frmCtrl, hWndForm) Next frmCtrl

I can't figure out what to do. Could You help?

cristianbuse commented 2 years ago

Hi @piotrpoletek ,

It's very difficult for me to say what is wrong as the code works fine on my computers.

I would suspect this is a runtime error as the code compiles fine. Can you confirm?

If you step through code line by line, does the issue happen for a specific control?

Thanks!

piotrpoletek commented 2 years ago

Hi,

Could you check in attached file? Thanks.

Mouse_Scroll.zip

cristianbuse commented 2 years ago

@piotrpoletek

The actual class has a default instance. You can see that on line 8 of the MouseOverControl class.

However, those attributes do not come through when you just copy-paste code. So, you must import the module instead.

Just download the zip, extract the files and then just import the class file in your project (not copy-paste code).

piotrpoletek commented 2 years ago

@cristianbuse First issue solved. Module works when imported. Mouse gets hooked/unhooked, but scrolling is not working. Thanks for Your time. Mouse_Scroll.zip .

cristianbuse commented 2 years ago

@piotrpoletek

You should not use the default instance of a userform. Maybe read this article to understand why.

I updated your file and it works.

Mouse_Scroll.zip

piotrpoletek commented 2 years ago

@cristianbuse I managed to implement it in my form. Thanks a lot again. I'll explore default instances.

cristianbuse commented 2 years ago

@piotrpoletek

Your message came through to my email but not here.

Anyway, try replacing this:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        Call save
    End If
End Sub

with this:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        save
        Cancel = True
        Me.Hide
    End If
End Sub

For me it works even without this change but please do try and let me know if it fixes your issue.