By: Shamima Sultana

In reply to Emily.

Hello Emily,

Thanks for following up. Sure! Let me explain more clearly how to get the mouse wheel to work in a ListBox created in VBA (UserForm) using ActiveX control.

Step-by-Step Setup
Step 1:
1. Insert a UserForm and ListBox
2. Press Alt + F11 to open the VBA Editor.
3. Right-click on your project > Insert > UserForm.
4. From the toolbox, drag and drop a ListBox onto the UserForm. (This is an ActiveX-style ListBox by default in UserForms.)
5. Name it ListBox1 if it’s not already.

Step 2:
1. Create a Class to Handle Scroll-Like Behavior
2. In the VBA editor, go to Insert > Class Module.
3. In the Properties window (F4), change the name to clsMouseWheel.

Paste this code into the class:

' In Class Module: clsMouseWheel
Public WithEvents LB As MSForms.ListBox

Private Sub LB_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyPageUp Then
LB.TopIndex = Application.WorksheetFunction.Max(0, LB.TopIndex - 5)
ElseIf KeyCode = vbKeyPageDown Then
LB.TopIndex = LB.TopIndex + 5
End If
End Sub

Step 3:
1. Connect the Class in Your UserForm
2. In the UserForm code, add this:

Dim mw As clsMouseWheel

Private Sub UserForm_Initialize()
Set mw = New clsMouseWheel
Set mw.LB = Me.ListBox1

' Fill the ListBox with example data
Dim i As Integer
For i = 1 To 100
Me.ListBox1.AddItem "Item " & i
Next i
End Sub

Important Notes:
1. Unfortunately, VBA UserForms do not natively support the mouse wheel unless you use advanced Windows API calls (which get quite technical and need 32-bit vs 64-bit handling).
2. This solution mimics scrolling by using the Page Up / Page Down keys. It’s the most stable workaround in standard VBA.

If you’re not seeing the ListBox scroll or can’t activate it:
1. Double-check that you’re using a UserForm ListBox (not one directly on a worksheet).
2. Ensure ActiveX controls are enabled (especially if your Excel settings or security options are blocking them).

Regards
ExcelDemy