我看不到我的动态标签,但我知道它们在那里

时间:2015-02-12 04:42:42

标签: vba dynamic multipage

我已经使用了一些代码来在多页上放置一些标签。我可以告诉第五个标签放置后发生了什么事情,因为在例程的第5次迭代之后帧中断了,但没有任何东西可见。

Sub pgSSRs()
    Dim MPg As MSForms.MultiPage
    Dim NewLabel As MSForms.Label
    Dim Listarray As Integer
    Dim labelCounter As Long

    Listarray = ThisWorkbook.Sheets("SSRs").Range("SSRs").Rows.Count

    'MsgBox (Listarray & " SSRs")
    'Top = 50

    For labelCounter = 1 To Listarray
        Set NewLabel = UserForm1.Controls.Add("forms.label.1", "Test" & labelCounter, True)
        With NewLabel
            .Visible = True
            .Caption = "Test" & labelCounter
            .Height = 30
            .Left = 700
            .Width = 50
            .Top = Top + 10 * labelCounter
            MsgBox (.Top & " iteration")
        End With
    Next

    'MsgBox ("this is the SSR Page!")

End Sub

有人可以帮我看看这些标签吗?最终我想从工作表上的单元格中读取每个标签,但是在简单的东西上遇到了麻烦......

2 个答案:

答案 0 :(得分:0)

您需要启用标签:

.Enabled = True

然后你应该在最后展示它?

UserForm1.Show

答案 1 :(得分:0)

目前还不清楚你想要做什么,但这对我有用(它将标签添加到多页控件的第一页)

您必须将标签直接添加到控件包含的“页面”中,而不是将它们添加到用户表单本身的“根”级别。

Sub pgSSRs()

    Dim MPg As MSForms.MultiPage
    Dim NewLabel As MSForms.Label
    Dim Listarray As Integer
    Dim labelCounter As Long

    Listarray = 5 'ThisWorkbook.Sheets("SSRs").Range("SSRs").Rows.Count

    Set MPg = UserForm1.MultiPage1

    For labelCounter = 1 To Listarray
        'add labels to first page
        Set NewLabel = MPg.Pages(0).Controls.Add("forms.label.1", "Test" & labelCounter, True)
        With NewLabel
            .Visible = True
            .Caption = "Test" & labelCounter
            .Height = 30
            .Left = 10
            .Width = 50
            .Top = 20 + (10 * labelCounter)
            Debug.Print .Top & " iteration"
        End With
    Next

    UserForm1.Show

    'MsgBox ("this is the SSR Page!")

End Sub