Code for mouse wheel in VBA

Colleen45

Active Member
Joined
Jul 22, 2007
Messages
495
What VBA code do I use to use the mouse wheel on my own form, or is on one of the properties
Thank you
 
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

@YasserKhalil
Please do not ask members here to help you on other sites.
If you want help, please start new thread giving full details & include the cross-post link
Thanks
 
Last edited:
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

I am so sorry but I tried to send PM (His InBox is ful) and I need help at this topic
 
Upvote 0
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

You have been around this site (& others) long enough to know the rules.
Please abide by them, that includes sending unsolicited PMs
 
Upvote 0
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

@Jaafar Tribak
Hi Jaafar! I had a look at your last post and I liked you loop aproach with the PeekMessage. Too bad VBA is not multi-threaded and you have to use DoEvents. I also had a look on a few of your older posts regarding hooking and subclassing and it seems you have got to some very interesting solutions. I liked the C++ DLL approch packed in VBA bite arrays. However, I have chosen to follow one of your indirect advices and detect the VBE window thus solving the unhandled error problem. The application won't crash when an unhandled error occurs but debbuging will still crash it. For me it is sufficient for now as I do not need to debug a Form and Hook at the same time. The function is called IsVBEActive and you can find it at the bottom of the module
https://github.com/cristianbuse/VBA-UserForm-MouseScroll/blob/master/Code Modules/MouseScroll.bas

Regards

 
Upvote 0
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

@Cristian Buse

Your IsVBEActive function won't prevent crashing the whole excel application if the user presses CTRL+BREAK keys .

You could avoid this potential nasty crashing by adding a small loop in the userform activate event as follows :

Add this to your already existing code :

Code:
Option Explicit

Private bXit As Boolean

Private Sub UserForm_Activate()

   [B][COLOR=#008000] 'Any pre-existing UserForm_Activate event code goes here[/COLOR][/B]

    Call DoLoop
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    bXit = True
End Sub


Private Sub DoLoop()
    Do
        DoEvents
    Loop Until bXit
End Sub

The loop won't interfere with the normal use and functionning of the userform.
 
Last edited:
Upvote 0
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

@Jaafar Tribak
Thanks for checking it out. I haven't thought of the User breaking.
I don't want to use a loop which is very costly so instead I used the Application.EnableCancelKey = 0 (disabled) which works for Excel and Word and I called it with:
Code:
On Error Resume Next
CallByName Application, "EnableCancelKey", VbLet, 0
On Error GoTo 0
so that it still compiles for other Applications.

All the best
 
Upvote 0
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

Code:
On Error Resume Next
CallByName Application, "EnableCancelKey", VbLet, 0
On Error GoTo 0

I hadn't tought of the EnableCancelKey Property ... Yes!! That's a much better approach than running a continious loop .. CallByName is not necessary just don't use the constant xlDisabled and use 0 instead.

Great stuff.
 
Upvote 0
Re: Code for mouse wheel to scroll Frame on a Userform in VBA

CallByName will compile under Access or PowerPoint but Application.EnableCancelKey will not. That is the only reason why I used it.

Again thanks for all your help!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top