小编ICo*_*sed的帖子

使用vba在模块中以编程方式创建表单

我想以编程方式使用VBA在模块中创建用户表单.我是一个新手,没有经验,所以我尝试了几个例子,但他们没有满足我的要求.

我只想要宏

  • 使用VBA在模块中创建用户表单
  • 有一个带有一些数据的ListBox
  • 有一个带侦听器的CommandButton

这是我使用的代码

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和按钮添加到表单.

excel vba excel-vba

12
推荐指数
1
解决办法
5万
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1