验证 Excel 用户窗体中特定多页页面上的文本框

肯尼斯·布兰农

因此,我正在努力确保所有内容TextBoxes都已填写。但是,我只希望此脚本检查MultiPageExcel页面上的某个页面UserForm下面是我正在使用的代码,但它正在检查TextBox用户表单中的每一个,而不是特定页面上的。还有一张图给大家看看。我圈出了名为“Box”的页面,它也是第 3 页,我想在验证TextBoxes验证时参考TextBoxes它。

用户窗体快照

Private Sub CommandButton2_Click()
    Dim Ctrl As Control
    Dim Answer1 As VbMsgBoxResult
    ' Checks to make sure data has been entered into all fields on the UserForm Page
    For Each Ctrl In Me.Controls
        If TypeOf Ctrl Is MSForms.TextBox Then
            If Ctrl.Value = vbNullString Then
                MsgBox "All fields must be completed before the information can be updated.", vbOkay + vbExclamation, "Missing Information"
                Exit Sub
            End If
        End If
    Next
    ' Displays box with Yes or No asking if they are sure they want to save and close document
    Answer1 = MsgBox("Doing this will overwrite the previous data that was entered. Are you sure you want to do this?", vbYesNo + vbExclamation, "Update Cabinet Information")
    ' Writes the new data entered into the workbook
    If Answer1 = vbYes Then
        Sheet5.Range("B1").Value = TextBox1.Value
        If IsDate(TextBox2.Value) Then
            Sheet5.Range("B2").Value = Format(TextBox2.Value, "mm/dd/yyyy")
        Else
            MsgBox "One or more fields have an incorrect date format. Dates must be entered in this formay mm/dd/yyyy."
            Exit Sub
        End If
        Sheet5.Range("B3").Value = TextBox3.Value
        Sheet5.Range("G1").Value = TextBox4.Value
        If IsDate(TextBox5.Value) Then
            Sheet5.Range("G2").Value = Format(TextBox5.Value, "mm/dd/yyyy")
        Else
            MsgBox "One or more fields have an incorrect date format. Dates must be entered in this formay mm/dd/yyyy."
            Exit Sub
        End If
        Sheet5.Range("G3").Value = TextBox6.Value
        Sheet5.Range("J1").Value = TextBox7.Value
        If IsDate(TextBox8.Value) Then
            Sheet5.Range("J2").Value = Format(TextBox8.Value, "mm/dd/yyyy")
        Else
            MsgBox "One or more fields have an incorrect date format. Dates must be entered in this formay mm/dd/yyyy."
            Exit Sub
        End If
        Sheet5.Range("J3").Value = TextBox9.Value
        Sheet5.Range("M1").Value = TextBox10.Value
        If IsDate(TextBox11.Value) Then
            Sheet5.Range("M2").Value = Format(TextBox11.Value, "mm/dd/yyyy")
        Else
            MsgBox "One or more fields have an incorrect date format. Dates must be entered in this formay mm/dd/yyyy."
            Exit Sub
        End If
        Sheet5.Range("M3").Value = TextBox12.Value
        Sheet5.Range("P1").Value = TextBox13.Value
        If IsDate(TextBox14.Value) Then
            Sheet5.Range("P2").Value = Format(TextBox14.Value, "mm/dd/yyyy")
        Else
            MsgBox "One or more fields have an incorrect date format. Dates must be entered in this formay mm/dd/yyyy."
            Exit Sub
        End If
        Sheet5.Range("P3").Value = TextBox15.Value
        Sheet5.Range("S1").Value = TextBox16.Value
        If IsDate(TextBox17.Value) Then
            Sheet5.Range("S2").Value = Format(TextBox17.Value, "mm/dd/yyyy")
        Else
            MsgBox "One or more fields have an incorrect date format. Dates must be entered in this formay mm/dd/yyyy."
            Exit Sub
        End If
        Sheet5.Range("S3").Value = TextBox18.Value
    End If
End Sub
多梅尼克

您需要引用 MultiPage 对象的 Pages 集合。因此,假设多页控件名为 MultiPage1,您需要按如下方式修改该行...

For Each Ctrl In Me.MultiPage1.Pages(2).Controls

请注意,Pages 集合的索引是从 0 开始的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Asp.net验证。仅允许用户在文本框中输入特定数字

来自分类Dev

Excel用户窗体文本框常量设置焦点

来自分类Dev

仅在Excel中对文本进行数据验证

来自分类Dev

Excel VBA文本框时间验证为[h]:mm

来自分类Dev

使用特定字母在文本框中输入验证

来自分类Dev

在没有按钮事件(如Excel)的WPF程序中验证文本框

来自分类Dev

Excel中的双重标准数据验证

来自分类Dev

EXCEL验证用户表单文本框

来自分类Dev

Excel中IP地址的数据验证

来自分类Dev

VBA Excel-文本框验证

来自分类Dev

验证Excel工作表中的数据

来自分类Dev

特定字符的Excel验证码

来自分类Dev

Excel中的高级动态验证列表

来自分类Dev

Excel数据验证下拉框

来自分类Dev

验证用户窗体文本框条目的格式

来自分类Dev

在C#中验证Excel数据

来自分类Dev

在Java中的MS Excel中验证数据

来自分类Dev

在Excel中限制和验证日期格式

来自分类Dev

如何验证Windows窗体C#中特定模式的文本框

来自分类Dev

基于值矩阵的Excel中的数据验证

来自分类Dev

Excel VBA验证文本框中的特定格式

来自分类Dev

Excel数据验证(文本长度)

来自分类Dev

使用Excel VBA在CSV中验证特定数据

来自分类Dev

使用循环来验证Excel用户窗体上的条目?

来自分类Dev

Excel:在 VBA 子文件中设置验证

来自分类Dev

带有整数和特定文本的 Excel 数据验证

来自分类Dev

验证:在 VBA Excel 的文本框中只能输入一次特定的单词

来自分类Dev

验证用户表单上的文本框条目(Excel VBA)

来自分类Dev

在 ruby on rails 中验证 excel 表