我在Excel VBA中使用MultiPage控件创建向导。
它有4页,我想验证每个页面的数据。
对于第2页,我正在验证文本框,确保它们不会因以下代码而空:
Private Sub validaPasso2()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeOf cCont Is MSForms.TextBox Then
If cCont.Value = vbNullString Then
MsgBox "caixa vazia"
End If
End If
Next
End Sub
但是,这是检查表单中的所有文本框,我只想检查Page2。因此,我应该如何表达For Each cCont In Me.Controls
?
Each cCont In Me.Controls in Page2 only
答案 0 :(得分:1)
Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.MultiPage1.Pages(0).Controls
If TypeName(cCont) = "TextBox" Then
'DO STUFF HERE
End If
Next cCont
End Sub
找到here