【发布时间】:2019-05-12 15:07:13
【问题描述】:
我想将 multicheckbox 中的内容(在用户表单中创建)传递给模块以供进一步使用。 代码中的这个函数是:
在模块中:
Public pass1 As Boolean
Public pass2 As Boolean
Public pass3 As Boolean
Public pass4 As Boolean
Public Sub MultiCheckBoxes()
Dim varArraySelected As Variant
Dim ivar As Long
varArraySelected = Array()
UserForm1.Show
ivar = 0
If pass1 = True Then
ReDim Preserve varArraySelected(0 To ivar)
varArraySelected(ivar) = "Fase 1"
ivar = ivar + 1 'Advance the counter to next array item
End If
If pass2 = True Then
ReDim Preserve varArraySelected(0 To ivar) 'Reset the array dimension on each iteration of loop
varArraySelected(ivar) = "Fase 2" 'Add value in Column B to Array
ivar = ivar + 1 'Advance the counter to next array item
End If
If pass3 = True Then
ReDim Preserve varArraySelected(0 To ivar) 'Reset the array dimension on each iteration of loop
varArraySelected(ivar) = "Fase 3" 'Add value in Column B to Array
ivar = ivar + 1 'Advance the counter to next array item
End If
If pass4 = True Then
ReDim Preserve varArraySelected(0 To ivar) 'Reset the array dimension on each iteration of loop
varArraySelected(ivar) = "Fase 4" 'Add value in Column B to Array
End If
Unload UserForm1
End Sub
在用户窗体中:
Option Explicit
Private Sub CheckBox1_Click()
End Sub
Private Sub CheckBox2_Click()
End Sub
Private Sub CheckBox3_Click()
End Sub
Private Sub CheckBox4_Click()
End Sub
Private Sub CommandButton1_Click()
pass1 = UserForm1.CheckBox1.Value
pass2 = UserForm1.CheckBox2.Value
pass3 = UserForm1.CheckBox3.Value
pass4 = UserForm1.CheckBox4.Value
Unload UserForm1
End Sub
这里 'Fase 1',..., 'Fase 4' 是在 UserForm1 中创建的四个复选框中的文本内容。
运行 VBA 模块时,我收到错误“检测到不明确的名称:pass1”。如何解决问题?
提前致谢!
【问题讨论】:
-
您在工作簿的其他任何地方是否有第二个
pass1声明?
标签: excel vba checkbox parameter-passing userform