【问题标题】:How can I count "Checkboxes" in only Page1 in the UserForm1?如何仅在 UserForm1 的 Page1 中计算“复选框”?
【发布时间】:2018-11-09 17:49:31
【问题描述】:

如何使用 VBA 仅在 UserForm1 的 Page1 中计算“复选框”? 下面我的全部在第 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

【问题讨论】:

    标签: vba excel checkbox userform


    【解决方案1】:

    您可以在这里找到它们:

    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
    

    【讨论】:

    • 就这些了吗?我不知道“复选框”这个词可以在代码中删除。谢谢。
    • 没错,打败了我。但是,如果您只想计算复选框,则必须遍历页面上的控件并检查 Typename(ctl) = “Checkbox”
    • 糟糕。更新来了。谢谢!
    • 你能不能给我一个使用“IF”语句的建议?如果我只想选择,我只想计算 Page1 中的复选框。当我选择“Page2”时,下面的仍然有效。 If Me.MultiPage1..Pages(0).Enabled = True Then cnt = Me.MultiPage1.Pages(0).Controls.Count MsgBox cnt End If
    • 谢谢,它成功了。我想知道为什么它不是“Me.MultiPage1.Value = 1”
    猜你喜欢
    • 2020-03-01
    • 2020-02-17
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    相关资源
    最近更新 更多