【问题标题】:Excel VBA Userform CheckBoxes AccessExcel VBA 用户表单复选框访问
【发布时间】:2017-08-16 11:52:13
【问题描述】:

我正在以编程方式根据工作表范围内的行数创建用户表单(当前设置为固定数字以进行测试)。 然后用户选中他们想要检查的框并单击命令按钮。

使用下面的代码运行的用户表单有一个手动添加的命令按钮和一个复选框。其他复选框以编程方式添加。 我不知道如何从有问题的复选框中获取值。我只是收到一个错误,即“testbox”未定义。 我知道我错过了一些简单的东西......

有什么想法吗? 谢谢!

Option Explicit

Private Sub updateTablesBtn_Click()
    If CheckBox1.Value = True Then
        MsgBox "true"
    End If

    If testBox.Value = True Then
        MsgBox "true"
    End If
End Sub

Private Sub UserForm_Initialize()
    Dim chkBox As MSForms.CheckBox

    With formTableUpdate
        .Width = 150
        .Height = 200 '15 + 20 * (noOfVariants + 1) + 30
    End With

    Set chkBox = formTableUpdate.Controls.Add("Forms.CheckBox.1")
    With chkBox
        .Name = "testBox"
        .Caption = "test"
        .Left = 5
        .Top = 10
    End With

    With updateTablesBtn
        .Caption = "Update Tables"
        .Height = 25
        .Width = 76
        .Left = 38
        .Top = 30
    End With

End Sub

【问题讨论】:

    标签: vba excel checkbox userform


    【解决方案1】:

    试试这个:

    Dim chkBox As Control
    
    For Each chkBox In formTableUpdate.Controls
        If chkBox.Name = "testBox" Then
            MsgBox chkBox.Caption & " has the value " & chkBox.Value
        End If
    Next chkBox
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-23
      • 2011-02-07
      • 2020-10-28
      • 2016-07-02
      • 1970-01-01
      • 2015-02-20
      • 1970-01-01
      相关资源
      最近更新 更多