Excel VBA Userformcheckbox访问
我正在编程创build一个基于工作表范围内的行数(当前设置为一个固定的数字进行testing)的用户窗体。 然后用户检查他们想要检查的框,然后点击命令button。
用下面的代码运行的用户表单有一个命令button和一个手动添加的checkbox。 其他checkbox以编程方式添加。 我无法弄清楚如何从创build的checkbox有问题的价值。 我只是得到一个错误,“testing箱”没有定义。 我知道我错过了一些简单的…
有什么想法吗? 谢谢!
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
尝试这个:
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
- 数百个checkbox从True / False更改为Yes / No
- CheckBox来限制数据validation列表
- VBA excel用1个macros控制多个checkbox
- 如果必填字段为空,Excel / VBA将取消选中checkbox
- 是否有可能在Excel VBA中返回checkbox的名称?
- 用vba excel打开一个表单checkbox
- 用户自定义命令button,基于checkbox复制True / False
- 在VBA中创buildcheckbox,设置“单元格移动和大小”
- popup式错误消息(macros) – 通过checkboxselect进行更新 – Excel 2010