Label is one of the UserForm control. You can select and drag Label on the UserForm. Label is used to display show text or information. It can be title, caption, etc. It can be used on the UserForm. You can see how it works and more details about Userform Label Control on the UserForm in the following chapter.

VBA ActiveX Label_Control on the UserForm

Please find more details about VBA ActiveX Label Control on the UserForm.

    1. Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
    2. Go To Insert Menu, Click UserForm. Please find the screenshot for the same.

Excel VBA UserForm CheckBox

    1. Drag the label control on the Userform from the Toolbox. Please find the screenshot for the same.

Label Excel VBA ActiveX Control3

    1. Click on the properties.
    2. On the left side find ‘Caption’ from the available properties.
    3. On the right side mention as ‘Welcome!’. Please find the below screen shot for the same.

Label Excel VBA ActiveX Control4

  1. Like this you can add number of Label controls on the UserForm according to your requirement.

Add dynamic Label_Control on the UserForm using VBA

Please find the following steps and example code, it will show you how to add dynamic Label control on the userform.

    1. Add Label and CommandButton on the userform from the toolbox.
    2. Right click on the CommandButton, click properties
    3. Change the CommandButton caption to ‘Create_Label ’
    4. Double click on the CommandButton
    5. Now, it shows the following code.
Private Sub CommandButton1_Click()
 
End Sub
    1. Call the below procedure named ‘Add_Dynamic_Label ’ and find the below procedure to run.
Private Sub CommandButton1_Click()
    Call Add_Dynamic_Label 
End Sub

Procedure to call in the CommandButton:

Sub Add_Dynamic_Label()
    'Add Dynamic Label and assign it to object 'Lbl'
    Set lbl = UserForm2.Controls.Add("Forms.Label.1")
    
    'Assign Label Name
    lbl.Caption = "Dynamic Label"
    
    'Label Border Style
    lbl.BorderStyle = 2
    
    'Label Position
    lbl.Left = 10
    lbl.Top = 10
End Sub
    1. Now, click F5 to run the macro, click ‘Create_Label ’ button to see the result.
    2. You can see the created dynamic Label which is shown in the following screen shot.

output:

Label Excel VBA ActiveX Control1

Delete Label_Control on the UserForm using VBA

Please find the below code, it will show you how to delete or remove the control on the UserForm. In the below example, its deleting the Label named ‘New Label’ which is on the UserForm named ‘UserForm4’. We can use Remove method to delete the controls which are created during run time. Controls which are created during design time cannot be deleted using this method. Please find the below example and screen shots for better understand.
Code 1: Adding control During Run Time

Private Sub CommandButton1_Click()
    'We can use Add method to add the new controls on run time
    Set lblBtn = Me.Controls.Add("Forms.Label.1")
    With lblBtn
        .Top = 20
        .Left = 20
        .Caption = "New Label"
        .Name = "lblNew1"
    End With
    MsgBox "New Label Added"
End Sub

lease find the below screen shot for your reference for the above macro and its output.
When we click on Add Command Button:

Label Excel VBA ActiveX Control6

Code 1: Deleting or Removing label_control which is created during run time.

Private Sub CommandButton2_Click()
    'We can use Remove method to delete the controls which are created during run time
    'Note: Controls which are created on design time cannot be deleted using this method
    Me.Controls.Remove ("lblNew1")
    MsgBox "New Label Deleted"
End Sub

Please find the below screen shot for your reference for the above macro and its output.
When we click on Delete Command Button:

Label Excel VBA ActiveX Control5

120+ Professional Project Management Templates!
Save Up to 85% LIMITED TIME OFFER

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Browse All Templates
Excel VBA Project Management Templates

All-in-One Pack
120+ Project Management
Premium Templates
View Details

Essential Pack
50+ Project Management
Premium Templates
View Details
50+ Excel
Project Management
Templates Pack
View Details
50+ PowerPoint
Project Management
Templates Pack
View Details
25+ MS Word
Project Management
Templates Pack
View Details
Ultimate Project Management Template
View Details
Ultimate Resource Management Template
View Details
Project Portfolio Management Templates
View Details

Share This Story, Choose Your Platform!

Comments are closed.