【问题标题】:VBA userform - add label to frameVBA 用户窗体 - 将标签添加到框架
【发布时间】:2021-05-12 22:47:14
【问题描述】:

我在一个大框架内有六个小框架,我创建了一个按钮来使用这些代码在大框架内添加新的小框架:

For Each cCont In Me.Controls
    If TypeName(cCont) = "Frame" Then
        lCount = lCount + 1
    End If
Next cCont

If lCount = 6 Then
    '384 is the top property of No.6 frame 
    '72 is every small frame distance
    top = 384 + 72
ElseIf lCount > 6 Then
    top = 384 + (72 * (lCount - 5))
End If

Set addBtn = bigFrame.Controls.Add("Forms.Frame.1")
With addBtn
    .Height = 66
    .Left = 6
    .top = top
    .Width = 312
    .name = "frameName" & lCount + 1
    .Caption = "frameName - " & lCount + 1
    .Font.Size = 12
End With

所以这是我的问题,如何在新的小框架中添加新标签? 我知道代码应该是这样的:

Set label = bigFrame.frameName.Controls.Add("Forms.Label.1")

添加新的小框后,新的小框的名称应该是frameName7。我应该在代码中写什么,以便在按下按钮时添加一个带有标签的小框架。谢谢。

【问题讨论】:

    标签: vba label frame userform


    【解决方案1】:

    您已经有了对新插入框架的引用,因此您可以:

    Dim myLabel As MSForms.Label
    Set myLabel = addBtn.Controls.Add("Forms.Label.1", "MyLabel", True)
    

    或直接从用户表单使用:

    Set myLabel = Me.Controls("FrameName").Controls.Add("Forms.Label.1", "MyLabel", True)
    

    【讨论】:

      猜你喜欢
      • 2010-10-08
      • 1970-01-01
      • 2017-11-17
      • 2015-01-02
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2012-11-04
      • 2020-09-25
      相关资源
      最近更新 更多