0

I have used some code from here to place some labels on a multipage. I can tell after the 5th label is placed that something is happening because there is a break in the frame after the 5th iteration of the routine, but nothing is visible.

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

Can anyone provide assistance in helping me see these labels? Eventually I want to make each label read from a cell on a worksheet, but having trouble with the simple stuff...

hart143
  • 21
  • 4

2 Answers2

0

You need to Enable the labels:

.Enabled = True

Then you should show it at the end?

UserForm1.Show

PatricK
  • 6,375
  • 1
  • 21
  • 25
0

It's pretty unclear exactly what you want to do, but this worked for me (it added labels to the first page of the multi-page control)

You have to add the labels directly to the "page" contained by the control, and not add them to the "root" level of the userform itself.

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
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Thank you for the reply. I eventually stopped trying to use multipage and went to multiple user forms. I still had trouble for quite awhile until I realized that for new label I needed to point to the frame and not the user form. Thank you. – hart143 Feb 18 '15 at 15:58