尝试自动完成ActiveX ComboBox时Excel崩溃 [英] Excel crash when trying to Autocomplete an ActiveX ComboBox
问题描述
我在工作表上有一个ActiveX Combobox控件,这是_Change
事件代码
I have an ActiveX Combobox control on a worksheet and this is the _Change
event code
Private Sub ComboBox1_Change()
Me.ComboBox1.ListFillRange = "ItemSearch"
Me.ComboBox1.DropDown
End Sub
当我使用键盘上/下键在列表中移动时,它会自动退出Excel.
When I use keyboard up/down key to move through the list it automatically quits Excel.
有人知道这个问题的解决方案吗?我基本上想要一个动态的ComboBox.
Does anyone know the solution to this problem? I basically want a dynamic ComboBox.
推荐答案
更改所选选项时,您将强制更新Combobox的可能值,
这就是为什么它崩溃的原因.
You are forcing Combobox's possible values to update when you change the selected option,
that is why it's crashing.
在这种情况下,您可以尝试保留Me.ComboBox1.DropDown
.
You can try to keep Me.ComboBox1.DropDown
in that event.
但是.ListFillRange
应该在另一个事件中:
But the .ListFillRange
should be in another event :
- Workbook_Open
- Workbook_SheetChange
- Worksheet_SelectionChange
- Worksheet_Change
如果您尝试使用某种自动完成行为,则可以使用内置属性:
If you're attempting to have a kind of AutoComplete behavior, you can use a built-in property :
- 右键单击控件,再单击属性"
- 在打开的属性"窗口中,找到
MatchEntry
属性 - 将其设置为
0 - fmMatchEntryFirstLetter
- Right-click on the Control, click on Properties
- In the opened Properties window, find the
MatchEntry
property - Set it to
0 - fmMatchEntryFirstLetter
这篇关于尝试自动完成ActiveX ComboBox时Excel崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!