VBA 用户窗体列表框双击事件
VBA Userform listbox double click event
我有一个带有列表框的用户表单,其中显示了 table 中的所有项目。
列表框有一个双击事件,其中;
如果双击的行包含文本,它会打开一个编辑表单。
如果双击的行为空,则会显示一个消息框,说明 "the item is not valid for editing."
我想为此添加一项新功能,如果行中的某个单元格包含 "closed",则会显示一个消息框,提示“此项目已关闭且无法编辑。
我不太擅长 VBA,如果能提供任何帮助,我将不胜感激。下面是我目前的代码。
Private Sub RiskLogReviewListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Checks if the selected row is empty and outputs a message box if it is
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) = 0 Then _
MsgBox "The selected item is empty and not a valid entry for editing"
'Checks if the selected row is closed and outputs a message box if it is
If RiskLogReviewListBox.Column(11, 0) = "closed" Then _
MsgBox "The selected item is closed and not a valid entry for editing"
'Checks if the selected row is populated
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) > 0 Then
提前致谢:)
找到解决方案
Private Sub RiskLogReviewListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long
'Checks if the selected row is empty and outputs a message box if it is
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) = 0 Then _
MsgBox "The selected item is empty and not a valid entry for editing"
'Checks if the selected row is closed and outputs a message box if it is
If (RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 10)) = "closed" Then
MsgBox "The selected item is closed and not a valid entry for editing"
Exit Sub
Else
'Checks if the selected row is populated
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) > 0 Then
替换
If RiskLogReviewListBox.Column(11, 0) = "closed" Then _
和
If Instr(RiskLogReviewListBox.Column(11, 0), "closed") > 0 Then _
但是,我想如果出现以上两种情况,你的代码肯定是存在的。因此,我还建议在消息后使用 Exit Sub
...
我有一个带有列表框的用户表单,其中显示了 table 中的所有项目。 列表框有一个双击事件,其中; 如果双击的行包含文本,它会打开一个编辑表单。 如果双击的行为空,则会显示一个消息框,说明 "the item is not valid for editing."
我想为此添加一项新功能,如果行中的某个单元格包含 "closed",则会显示一个消息框,提示“此项目已关闭且无法编辑。
我不太擅长 VBA,如果能提供任何帮助,我将不胜感激。下面是我目前的代码。
Private Sub RiskLogReviewListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Checks if the selected row is empty and outputs a message box if it is
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) = 0 Then _
MsgBox "The selected item is empty and not a valid entry for editing"
'Checks if the selected row is closed and outputs a message box if it is
If RiskLogReviewListBox.Column(11, 0) = "closed" Then _
MsgBox "The selected item is closed and not a valid entry for editing"
'Checks if the selected row is populated
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) > 0 Then
提前致谢:)
找到解决方案
Private Sub RiskLogReviewListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long
'Checks if the selected row is empty and outputs a message box if it is
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) = 0 Then _
MsgBox "The selected item is empty and not a valid entry for editing"
'Checks if the selected row is closed and outputs a message box if it is
If (RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 10)) = "closed" Then
MsgBox "The selected item is closed and not a valid entry for editing"
Exit Sub
Else
'Checks if the selected row is populated
If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) > 0 Then
替换
If RiskLogReviewListBox.Column(11, 0) = "closed" Then _
和
If Instr(RiskLogReviewListBox.Column(11, 0), "closed") > 0 Then _
但是,我想如果出现以上两种情况,你的代码肯定是存在的。因此,我还建议在消息后使用 Exit Sub
...