I need to combine a topic I found on stackoverflow and Mouse scroll in UserForm.
For my UserForm
I activate (hook) the scroll wheel and deactivate (unhook) the scroll wheel when I close the Userform
.
For the next update of the application, colleagues want a minimize button. I have achieved this through the following topic; Minimize userform and create icon on taskbar
But now when I minimize the Userform, the scroll is not unhooked (UnhookFormScroll
)
I did look into a solution where I use UserForm_Layout()
combined with IsIconic
(Link how that should be used, but instead I used UnhookFormScroll);
'The 5 lines of code beneath need to be somewhere else in the module of the
'form
Option Explicit
Private Declare Function IsZoomed Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function IsIconic Lib "user32" _
(ByVal hWnd As Long) As Long
Private Sub UserForm_Layout()
'I have edited the code so it works for whoever passes this post in the future
Dim hWnd as Long
If IsIconic(hwnd) Then
UnhookFormScroll
End if
If IsZoomed(hwnd) Then
HookFormScroll Me
End If
End Sub
This results in a error where Excel/VBA doesn't recognize the variable "hwnd
"