我正在尝试向用户表单动态添加按钮,但是用户表单只是空白。我已经尽可能地简化了代码的本质,以进行错误检查(不是对我有帮助)
Sub addLabel()
UserForm2.Show
Dim theLabel As Label
Dim labelCounter As Integer
For labelCounter = 1 To 3
Set Label = UserForm2.Controls.Add("Forms.Label.1", "Test" & labelCounter, True)
With theLabel
.Caption = "Test" & labelCounter
.Left = 10
.Width = 50
.Top = 10
End With
End Sub
是否可以检查按钮是否已添加但不可见?或为什么不添加它们。任何帮助,不胜感激。
几件事:
vbModeless
-否则代码将在UserForm2.Show
上停止>Label
的对象,然后使用With
上的theLabel
您将需要增加三个标签的位置,以避免重叠(我已经使用Top
完成此操作。]
Sub addLabel()
UserForm2.Show vbModeless
Dim theLabel As Object
Dim labelCounter As Long
For labelCounter = 1 To 3
Set theLabel = UserForm2.Controls.Add("Forms.Label.1", "Test" & labelCounter, True)
With theLabel
.Caption = "Test" & labelCounter
.Left = 10
.Width = 50
.Top = 10 * labelCounter
End With
Next
End Sub
end with
语句后,添加:
尝试下面的代码