Sub TaoForm()
Dim frmNewForm As Object
Dim TextBox As MSForms.TextBox
Dim NewButton As MSForms.CommandButton
Dim NewListBox As MSForms.ListBox
Dim NewCombo As MSForms.ComboBox
Dim LineCounter As Long
Application.VBE.MainWindow.Visible = False
[B][COLOR=Green]'Tao Form[/COLOR][/B]
Set frmNewForm = ThisWorkbook.VBProject.VBComponents.Add(3)
[B][COLOR=Green]'Tao Texbox[/COLOR][/B]
Set TextBox = frmNewForm.Designer.Controls.Add("Forms.TextBox.1")
[B][COLOR=Green] 'Tao CommandButton[/COLOR][/B]
Set NewButton = frmNewForm.Designer.Controls.Add("Forms.CommandButton.1")
[COLOR=DarkGreen][B]'Tao Listbox[/B][/COLOR]
Set NewListBox = frmNewForm.Designer.Controls.Add("Forms.ListBox.1")
[B][COLOR=Green] 'Tao ComBobox[/COLOR][/B]
Set NewCombo = frmNewForm.Designer.Controls.Add("Forms.ComboBox.1")
[B][COLOR=Green] 'Canh chinh texbox[/COLOR][/B]
With TextBox
.Text = "Xin chao cac ban !!!"
.Left = 0
.Top = 0
.Width = 228.75
End With
[B][COLOR=Green] 'Canh chinh CommandButton[/COLOR][/B]
With NewButton
.Caption = "Thoat"
.Left = 84
.Top = 132
End With
[COLOR=Green][B]'Thiet lap thuoc tinh cho combobox[/B][/COLOR]
With NewCombo
.Left = 0
.Top = 104
.Width = 228.75
.ColumnCount = 2
.ColumnWidths = "20;100"
.RowSource = "Data"
.Text = "Hay bam chon danh muc !"
End With
[B][COLOR=Green] 'Thiet lap thuoc tinh cho ListBox[/COLOR][/B]
With NewListBox
.Left = 0
.Top = 24
.Width = 228.75
.ColumnCount = 2
.ColumnWidths = "20;100"
.RowSource = "Data"
End With
[B][COLOR=Green] 'Chen code cho form[/COLOR][/B]
With frmNewForm.CodeModule
LineCounter = .countoflines
.insertlines LineCounter + 1, "Private Sub CommandButton1_Click()"
.insertlines LineCounter + 2, vbTab & "Unload Me"
.insertlines LineCounter + 3, "End Sub"
.insertlines LineCounter + 4, "Private Sub ComboBox1_Change()"
.insertlines LineCounter + 5, vbTab & "TextBox1 = ComboBox1.Column(1)"
.insertlines LineCounter + 6, "End Sub"
End With
End Sub