Hello,
I have a userform within a spreadsheet which, when loaded, uses vba to create a label (code below). I would like to add some code to this newly formed label, so that when it is clicked, the backcolor of the label changes to black i.e. RGB(0,0,0).
Code to create the label within the form (when the form is loaded):
Under this code in the vba editor, i added the following code, which i thought would change th backcolor of the label when clicked:
If i draw the label using the control toolbox and ignore the userform_activate code to create a new label, the form will behave as i would like.
Please can i ask your expert opinions on how you would approach this?
I have a userform within a spreadsheet which, when loaded, uses vba to create a label (code below). I would like to add some code to this newly formed label, so that when it is clicked, the backcolor of the label changes to black i.e. RGB(0,0,0).
Code to create the label within the form (when the form is loaded):
Code:
Private Sub UserForm_Activate()
Dim newlabel As MSForms.Label
Set newlabel = Me.Controls.Add("Forms.label.1")
With newlabel
.Name = "lbl_1"
.Top = 20
.Left = 12
.Height = 30
.Width = 30
.Caption = "Click to change"
End With
End Sub
Under this code in the vba editor, i added the following code, which i thought would change th backcolor of the label when clicked:
Code:
Sub lbl_1_Click()
lbl_1.Click = RGB(0, 0, 0)
End Sub
If i draw the label using the control toolbox and ignore the userform_activate code to create a new label, the form will behave as i would like.
Please can i ask your expert opinions on how you would approach this?