VBA Excel 组合框:下拉列表滚动问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19594075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Excel Combobox: drop-down list scrolling issue
提问by user2920603
I am running 32-bit Excel 2010. I have created multiple ActiveX Control combo boxes and they all have numbers of entries in their drop-down lists. The thing is that instead of using mouse click to scroll the list, I want to use the mouse scroll to scroll the list, but it actually doesn't work. When I scroll inside of the list, it scrolls the whole list down instead of the content in it. So does anyone know how to add this feature to it?
我正在运行 32 位 Excel 2010。我创建了多个 ActiveX 控件组合框,它们的下拉列表中都有条目数。问题是,我想使用鼠标滚动来滚动列表,而不是使用鼠标单击来滚动列表,但它实际上不起作用。当我在列表内滚动时,它会向下滚动整个列表而不是其中的内容。那么有谁知道如何添加这个功能呢?
回答by Neil
I used this method to stop the list detaching from the combo box and moving down the sheet with the mouse scroll. It actually disables the mouse scroll, but you can still move the mouse to select an item, and operaton the right scroll bar if it appears.
我使用这种方法来阻止列表从组合框分离并用鼠标滚动向下移动工作表。它实际上禁用了鼠标滚动,但您仍然可以移动鼠标来选择一个项目,如果它出现,则可以操作右侧的滚动条。
- Select the row(s) where you have placed the ActiveX combo Box and the sheet
- Type a named range in the Formula Bar, and press enter. eg: "rngJobRoleCombo"
- Right click on the control in Development mode, and select "View Code"
Select the control's GotFocus event
Private Sub cboJobRole_GotFocus() Me.ScrollArea = Range("rngJobRoleCombos").Address End Sub
Select the controls LostFocus event
Private Sub cboJobRole_LostFocus() Me.ScrollArea = "" End Sub
- 选择放置 ActiveX 组合框和工作表的行
- 在公式栏中键入命名范围,然后按 Enter。例如:“rngJobRoleCombo”
- 在开发模式下右键单击控件,然后选择“查看代码”
选择控件的 GotFocus 事件
Private Sub cboJobRole_GotFocus() Me.ScrollArea = Range("rngJobRoleCombos").Address End Sub
选择控件 LostFocus 事件
Private Sub cboJobRole_LostFocus() Me.ScrollArea = "" End Sub
This limits the mouse scroll to the cell range address of the worksheet while the control is in focus.
当控件处于焦点时,这会将鼠标滚动限制到工作表的单元格范围地址。