单击ListBox时宏将冻结



我使用的是Office Professional Plus 2019。我有一个ListBox,它有时会冻结宏。UserForm(AffDateSelector(有一个ListBox(DateSelectionList(和一个Button(Continue(。UserForm是通过AffDateSelector.show从驱动Sub调用的。表单的代码如下:

Option Explicit
Private Sub Continue_Click()

Dim lngCurrItem             As Long

'Assign the selected value to the public variable strClassDate.
For lngCurrItem = 0 To DateSelectionList.ListCount - 1
If DateSelectionList.Selected(lngCurrItem) = True Then
strClassDate = DateSelectionList.List(lngCurrItem)
End If
Next lngCurrItem

'Unload the form and return to the calling Sub.
Unload Me
End Sub
Private Sub DateSelectionList_Click()
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_initialize()

'Load ListBoxAccounts with the public variable strDateArray
With DateSelectionList
.List = strDateArray
End With

'Default the first row in DateSelectionList to be selected.
DateSelectionList.Selected(0) = True
End Sub

我一直在用F8来逐步完成代码。显示表单时,将执行UserForm_initialize((子命令,并正确显示数据。如果用户除了单击"继续"按钮之外什么都不做,则Continue_click((子命令将被执行,变量strClassDate将被填充,控制权将返回给调用子命令,一切正常。当用户选择列表中默认项目以外的项目时,问题就会出现。一旦用户单击ListForm,就会执行子DateSelectionList_Click((,但该子中没有任何内容,因此宏将冻结。如果我输入";伪码";到执行该行的DateSelectionlist_Click(((例如strClassDate=strClassDate(中,然后在执行End Sub语句时宏冻结。如何允许用户单击列表中的非默认项目,保持表单显示,并等待按下"继续"按钮?

代码很好。我打开了很多窗口,但弹出窗口没有出现。我正在VB编辑器中运行代码,但弹出菜单从未出现。当我按下Alt+Tab键时,它也没有出现在那个列表中。

最新更新