【问题标题】:Check more than one Frame for controls on a userform为用户窗体上的控件检查多个框架
【发布时间】:2021-12-09 07:20:07
【问题描述】:

我目前有一个在用户窗体背景故事上动态创建文本框的代码是here

在代码中,它检查表单上的单个框架是否有控件,如果有任何被勾选,则运行以下代码:

Function Addcheckboxes(emailtype)
Dim Ctrl As Control
Dim cont As Control
Dim i As Long
Dim h As Long
Dim intAppCount As Integer
Dim result As Long

' Loop through all the applications that have been selected with the email type and then create the appropriate email template on the userform lower box
If SpnColct.Count > 0 Then removeDynamicControls

For Each Ctrl In Me.Frame4.Controls
    If TypeOf Ctrl Is MSForms.CheckBox Then
        If Ctrl = True Then
            Call AddTextBox(Mid(Ctrl.Name, 4), emailtype)
            intAppCount = intAppCount + 1
        End If
    
    End If

Next

If intAppCount > 1 Then Me.Frame3.Caption = "Email Templates"

End Function

如何扩展它以使其同时检查用户窗体上的第 4 帧和第 5 帧?

提前谢谢你

【问题讨论】:

    标签: excel vba user-controls userform


    【解决方案1】:

    您可以按如下方式遍历每一帧...

    Dim Frm As Variant
    
    For Each Frm In Array(Me.Frame4, Me.Frame5)
        For Each Ctrl In Frm.Controls
            If TypeOf Ctrl Is MSForms.CheckBox Then
                If Ctrl = True Then
                    Call AddTextbox(Mid(Ctrl.Name, 4), emailtype)
                    intAppCount = intAppCount + 1
                End If
            
            End If
        Next
    Next Frm
    

    【讨论】:

    • 它在“for Each Frm In Array(me.frame4, me.frame5)”中请求一个对象
    • 其实Frm应该声明为Variant。请参阅我编辑后的帖子。
    • ... 和 Ctrl 应该声明为As MSForms.Control :-;
    • 所有排序谢谢大家
    猜你喜欢
    • 2023-03-10
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 2020-05-29
    • 1970-01-01
    • 2011-12-23
    相关资源
    最近更新 更多