cristianbuse / VBA-UserForm-MouseScroll

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

Excel 365 issues with the class module #12

Closed RFM-work closed 2 years ago

RFM-work commented 2 years ago

The mousescroll capability is very useful. After seeing the demo workbook, I'm trying to use your code in a test Excel workbook with 1 userform. I will only be using this with a native Excel 365 workbook & its native controls--specifically comboboxes.

Every line below that starts with the word Attribute is highlighted in red in my VB code Editor

 'Control types (MSForms.Control or MSForms.UserForm)
 Private WithEvents m_CheckBox As MSForms.CheckBox
 Attribute m_CheckBox.VB_VarHelpID = -1
 Private WithEvents m_ComboBox As MSForms.ComboBox
 Attribute m_ComboBox.VB_VarHelpID = -1
 Private WithEvents m_CommandButton As MSForms.CommandButton
 Attribute m_CommandButton.VB_VarHelpID = -1
 Private WithEvents m_Frame As MSForms.Frame
 Attribute m_Frame.VB_VarHelpID = -1
 Private WithEvents m_Image As MSForms.Image
 Attribute m_Image.VB_VarHelpID = -1
 Private WithEvents m_Label As MSForms.Label
 Attribute m_Label.VB_VarHelpID = -1
 Private WithEvents m_ListBox As MSForms.ListBox
 Attribute m_ListBox.VB_VarHelpID = -1
 Private WithEvents m_MultiPage As MSForms.MultiPage
 Attribute m_MultiPage.VB_VarHelpID = -1
 Private WithEvents m_OptionButton As MSForms.OptionButton
 Attribute m_OptionButton.VB_VarHelpID = -1
 Private WithEvents m_TabStrip As MSForms.TabStrip
 Attribute m_TabStrip.VB_VarHelpID = -1
 Private WithEvents m_TextBox As MSForms.TextBox
 Attribute m_TextBox.VB_VarHelpID = -1
 Private WithEvents m_ToggleButton As MSForms.ToggleButton
 Attribute m_ToggleButton.VB_VarHelpID = -1
 Private WithEvents m_UserForm As MSForms.UserForm
 Attribute m_UserForm.VB_VarHelpID = -1

 #Const DETECT_COMMON_CONTROLS = 0 'Turn to 1 to detect ListView controls
 #Const DETECT_INTERNET_CONTROLS = 0 'Turn to 1 to detect WebBrowser controls

 #If DETECT_COMMON_CONTROLS Then
 Private WithEvents m_ListView As MSComctlLib.ListView
 Attribute m_ListView.VB_VarHelpID = -1
 Private WithEvents m_TreeView As MSComctlLib.TreeView
 Attribute m_TreeView.VB_VarHelpID = -1
 #End If

 #If DETECT_INTERNET_CONTROLS Then
 Private WithEvents m_WebBrowser As SHDocVw.WebBrowser
 Attribute m_WebBrowser.VB_VarHelpID = -1
 Private WithEvents m_HTMLDocument As MSHTML.HTMLDocument
 Attribute m_HTMLDocument.VB_VarHelpID = -1
 #End If

How can i resolve this? Thank you.

RFM-work commented 2 years ago

I think the capabilities of the demo are impressive. I have found a simpler solution that will be easier to maintain over the long term so I will close this issue.

cristianbuse commented 2 years ago

Hi,

The Attribute keyword is only part of the text file - in your case in the .cls file. But those get hidden when you import the code module in VBA. I presume you did a copy-paste instead which will paste the extra attributes.

RFM-work commented 2 years ago

I selected all text & pasted, instead of an import. Thanks for following up. Good work on your part.

From: Cristian Buse @.> Sent: Tuesday, February 15, 2022 11:15 AM To: cristianbuse/VBA-UserForm-MouseScroll @.> Cc: Randy Meinert @.>; State change @.> Subject: Re: [cristianbuse/VBA-UserForm-MouseScroll] Excel 365 issues with the class module (Issue #12)

Caution:This email originated from outside of AZZ. Do not click links or open attachments unless you recognize the sender and know the content is safe.


Hi,

The Attribute keyword is only part of the text file - in your case in the .cls file. But those get hidden when you import the code module in VBA. I presume you did a copy-paste instead which will paste the extra attributes.

— Reply to this email directly, view it on GitHubhttps://github.com/cristianbuse/VBA-UserForm-MouseScroll/issues/12#issuecomment-1040472428, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXY7P7LWTR4UYCFFRWE2XFLU3J3Y5ANCNFSM5OOZC5PA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you modified the open/close state.Message ID: @.**@.>>

CONFIDENTIALITY NOTICE This message and any attachments are confidential and only for addressed recipients. If you are not the intended recipient; printing, retaining, reproducing, disclosing or using any information contained is prohibited. If you received this in error, please contact the sender immediately and destroy the message and any attachments or copies (electronic or hard copy). This e-mail shall not be considered a legally binding agreement or amendment to any agreement.

cristianbuse commented 2 years ago

No problem. Regarding your earlier mention about a simpler solution that is easier to maintain, I would love to hear back from you and understand what makes that easier to maintain. I've tried to make my solution as easy to use as possible (i.e. by calling a single line of code - EnableMouseScroll) but I would be glad to improve further if you have any ideas or found something that you liked somewhere else. Thanks!

RFM-work commented 2 years ago

First let me say that your solution is comprehensive and well done. Here’s my situation: I’m writing code to facilitate the creation of expense reports as a quasi-contractor for a firm. I’m not a full-time IT employee for the firm; I have other duties, but it happens that in a past life I did a bunch of VB coding. I need to be cognizant to maintain complexity of whatever I deliver at the lowest level possible, because I won’t always be available to troubleshoot issues. Simpler = more stable in my mind.

I began searching for a solution to the scrolling issue with comboboxes only because when people begin using this version, they might come to me asking why their mouse doesn’t work to scroll. After I run through testing my own stuff, I’ll either decide to incorporate code to address the mouse/combobox issue or tell them to “live with it”, depending on my evaluation

I found an alternate solution from this fellow:

' Jaafar Tribak @ MrExcel.com on 22/04/20 (updated on 18/08/2020) ' Code that enables mousewheel scrolling in vba Userform ComboBoxes.

From: Cristian Buse @.> Sent: Wednesday, February 16, 2022 3:25 AM To: cristianbuse/VBA-UserForm-MouseScroll @.> Cc: Randy Meinert @.>; State change @.> Subject: Re: [cristianbuse/VBA-UserForm-MouseScroll] Excel 365 issues with the class module (Issue #12)

Caution:This email originated from outside of AZZ. Do not click links or open attachments unless you recognize the sender and know the content is safe.


No problem. Regarding your earlier mention about a simpler solution that is easier to maintain, I would love to hear back from you and understand what makes that easier to maintain. I've tried to make my solution as easy to use as possible (i.e. by calling a single line of code - EnableMouseScroll) but I would be glad to improve further if you have any ideas or found something that you liked somewhere else. Thanks!

— Reply to this email directly, view it on GitHubhttps://github.com/cristianbuse/VBA-UserForm-MouseScroll/issues/12#issuecomment-1041233138, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXY7P7NPBSBT4MOMIH7EA7LU3NNPFANCNFSM5OOZC5PA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you modified the open/close state.Message ID: @.***>

CONFIDENTIALITY NOTICE This message and any attachments are confidential and only for addressed recipients. If you are not the intended recipient; printing, retaining, reproducing, disclosing or using any information contained is prohibited. If you received this in error, please contact the sender immediately and destroy the message and any attachments or copies (electronic or hard copy). This e-mail shall not be considered a legally binding agreement or amendment to any agreement.

cristianbuse commented 2 years ago

Oh yeah, I know this one. If you only want to use scroll for combo boxes then I suggest you go with Jaafar's solution. His solution does not involve a hook like mine does and so it cannot crash the host application. My solution can crash the application in rare cases. I did add a lot of extra checks to make sure it doesn't but it's just the nature of using hooks in VBA. Good luck and thanks for the kind words!

cristianbuse commented 11 months ago

Starting 76a384fb50d5bb2a5f6de49e287fe2fb774472d6 both Modal and Modeless forms are supported while debugging also works. Crashes do not occur anymore unless 'Reset; (IDE button) is pressed on purpose and only while stepping through code in the scope of MouseProc only. So, highly unlikey to crash