J
John
I'm trying to add a series of labels to a userform at runtime. I'm
stuck on a couple of aspects.
1. It looks like each label needs a unique name (true??). I'm not able
to do this.
2. When I set up each label, I need to assign it various properties.
Some of these are easy (e.g. height, width, etc.). But others don't
seem to be legal options (e.g. TextAlign)
Here is my non-working code:
'Generate Table of each problem attempted
Dim i As Integer
Dim newLbl As MSForms.Control
Dim lblName, strProb, strResult As String
For i = 1 To 1 'numAttempts
'Label for Question Number
lblName = "Forms.Label.Q" '& Right(i * 1000, 3) & ".1"
Set newLbl =
Me.Controls.Add(lblName) 'Run-time
error - Invalid Class String
newLbl.Caption = Range("results").Offset(i - 1, 0).Value
With newLbl
.Left = 54
.Top = 198
.Visible = True
.Height = 12
.Width = 24
.TextAlign = 'Not legal here??? How do I do this?
End With
Next i
Can anyone help? Thanks!
stuck on a couple of aspects.
1. It looks like each label needs a unique name (true??). I'm not able
to do this.
2. When I set up each label, I need to assign it various properties.
Some of these are easy (e.g. height, width, etc.). But others don't
seem to be legal options (e.g. TextAlign)
Here is my non-working code:
'Generate Table of each problem attempted
Dim i As Integer
Dim newLbl As MSForms.Control
Dim lblName, strProb, strResult As String
For i = 1 To 1 'numAttempts
'Label for Question Number
lblName = "Forms.Label.Q" '& Right(i * 1000, 3) & ".1"
Set newLbl =
Me.Controls.Add(lblName) 'Run-time
error - Invalid Class String
newLbl.Caption = Range("results").Offset(i - 1, 0).Value
With newLbl
.Left = 54
.Top = 198
.Visible = True
.Height = 12
.Width = 24
.TextAlign = 'Not legal here??? How do I do this?
End With
Next i
Can anyone help? Thanks!