我想以编程方式使用VBA在模块中创建用户表单.我是一个新手,没有经验,所以我尝试了几个例子,但他们没有满足我的要求.
我只想要宏
这是我使用的代码
Option Explicit
Sub MakeuserForm()
'Dim CommandButton1 As MsForms.CommandBarButton
'Dim ListBox1 As MsForms.ListBox
Dim UserForm1 As VBComponent
Set UserForm1 = ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
With UserForm1
.Properties("Height") = 100
.Properties("Width") = 200
On Error Resume Next
.Name = "My Form"
.Properties("Caption") = "This is your user form"
End With
ShowForm
End Sub
Sub ShowForm()
NewForm.Show
End Sub
Run Code Online (Sandbox Code Playgroud)
现在我不知道如何使用监听器将ListBox和按钮添加到表单.