MultiPage控件上的Excel用户表单验证

时间:2014-07-01 16:59:22

标签: excel vba

我在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

1 个答案:

答案 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

相关问题