如何在用户窗体 1 中仅计算第 1 页中的"Checkboxes"?



如何使用VBA仅在UserForm1的第1页中计算"复选框"? 我在下面计算了第 2 页和第 3 页中的所有内容。谢谢。

Private Sub CommandButton1_Click()
Dim cnt As Integer
cnt = Count.CheckBox()
If Me.MultiPage1.Enabled = True Then
Dim ctrl As msforms.Control, cnt As Long    
cnt = 0
For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is msforms.CheckBox Then
cnt = cnt + 1
End If
Next
MsgBox cnt
End If

你可以在这里找到它们:

Me.MultiPage1.Pages(0).Controls

如果您只想要号码:

MsgBox Me.MultiPage1.Pages(0).Controls.Count

更新
现在实际计算复选框

For Each ctrl In Me.MultiPage1.Pages(0).Controls
If TypeOf ctrl Is msforms.CheckBox Then
cnt = cnt + 1
End If
Next

最新更新