以前从未尝试过用户表单复选框,所以我什至不知道如何指向用户表单中的复选框。
这就是我现在所拥有的......我知道,我知道,这是完全错误的。请帮忙?
Private Sub Step1_Confirm_Click()
Dim i As Byte
Dim Done As Boolean
For i = 1 To 4
If Step1_(i).value = True Then
Done = True
End If
Next i
If Not Done = True Then
MsgBox "Please make sure you have done all"
End If
End Sub
基本上我有:
名为
的用户表单IOSP_Acc_R_Approval_Step1
4 个名为
Step1_1
的复选框;步骤1_2
;步骤1_3
;步骤1_4
名为
Step1_Confirm
的按钮如果没有选中所有复选框,我希望按钮显示错误 - 这意味着必须选中所有复选框......(以防我的英语太差而无法表达我的意思)
最佳答案
尝试下面的代码(代码中的解释作为注释):
Private Sub Step1_Confirm_Click()
Dim i As Long
Dim Ctrl As Control
' loop through all user_form control
For Each Ctrl In IOSP_Acc_R_Approval.Controls
If TypeName(Ctrl) = "CheckBox" Then ' check if control type is Check-Box
If Ctrl.Value = True Then ' check if check-box is checked
i = i + 1
End If
End If
Next Ctrl
If i < 4 Then ' not all 4 check-boxes are checked
MsgBox "Please make sure you have done all"
End If
End Sub
关于vba - (Excel 用户表单)检查用户表单中的所有复选框是否均已选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44535704/