excel - IsNull()、IsEmpty()、Application.WorksheetFunction.Istext() 为什么不能在组合框上工作?
问题描述
我已经尝试了以下几种变体,即使我没有在组合框中选择或键入任何内容,MsgBox 也永远不会运行。
变体1:
Private Sub CommandButton1_Click()
If IsNull(cmbPaidTo.Text) = True Then
MsgBox "Payee cannot be empty."
End If
Unload Me
UserForm1.Show
End Sub
变体2:
Private Sub CommandButton1_Click()
If IsNull(cmbPaidTo) = True Then
MsgBox "Payee cannot be empty."
End If
Unload Me
UserForm1.Show
End Sub
变体3:
Private Sub CommandButton1_Click()
If IsEmpty(cmbPaidTo.Text) = True Then
MsgBox "Payee cannot be empty."
End If
Unload Me
UserForm1.Show
End Sub
变体4:
Private Sub CommandButton1_Click()
If IsEmpty(cmbPaidTo) = True Then
MsgBox "Payee cannot be empty."
End If
Unload Me
UserForm1.Show
End Sub
变体5:
Private Sub CommandButton1_Click()
If Application.WorksheetFunction.IsText(cbxPaidTo.Text) = False Then
MsgBox "Payee cannot be empty."
End If
Unload Me
UserForm1.Show
End Sub
变体6:
Private Sub CommandButton1_Click()
If Application.WorksheetFunction.IsText(cbxPaidTo) = False Then
MsgBox "Payee cannot be empty."
End If
Unload Me
UserForm1.Show
End Sub
提交表单时组合框不应该为空,但我不明白为什么我不能让它工作。
我指向的组合框是没有文本标签的组合框。
解决方案
尝试:
If len(cmbPaidTo) = 0 Then
组合框的值将始终是字符串“”