我正在尝试通过从第一个组合框中选择一个项目来集中和扩展第二个组合框来优化excel中的用户窗体。
我尝试使用.Dropdown
,但收到错误The Object Invoked Has Disconnected from its Clients
。
到目前为止,我在UserForm中编写的代码如下:
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "First item"
.AddItem "second item"
End With
End Sub
Private Sub ComboBox1_Change()
Dim index As Integer
index = ComboBox1.ListIndex
ComboBox2.Clear
Select Case index
Case Is = 0
With ComboBox2
.AddItem "First subitem"
.AddItem "second subitem"
End With
Case Is = 1
With ComboBox2
.AddItem "First subitem on second item"
.AddItem "Second subitem on second item"
End With
End Select
ComboBox2.SetFocus
ComboBox2.DropDown
End Sub
此外,我已经在ThisWorkbook
部分
Private Sub Workbook_Open()
UserForm1.Show
End Sub
调试突出显示UserForm1.Show
,但仅当我使用ComboBox2.DropDown
行时才会出现错误。
我知道此错误不是很具体,但是我无法使代码正常工作。
注意:我已尽可能简化代码,以使错误仍然存在。