动态添加标签到用户窗体=空白用户窗体 [英] Dynamically Adding Labels to User Form = Blank UserForm
本文介绍了动态添加标签到用户窗体=空白用户窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向用户窗体动态添加按钮,但用户窗体刚刚出现空白。 Ive尽可能简化了错误检查的本质(不是它帮助我)
Sub addLabel()
pre>
UserForm2.Show
Dim theLabel As Label
Dim labelCounter As Integer
对于labelCounter = 1至3
Set Label = UserForm2.Controls.Add( Forms.Label.1,Test& labelCounter,True)
WithLabel
.Caption =Test& labelCounter
.Left = 10
.Width = 50
.Top = 10
结束
End Sub
有没有办法检查按钮是否已添加但不可见?或为什么他们不被添加。任何帮助非常感谢。
解决方案几件事:
- 您需要将您的UserForm显示为
vbModeless
- 否则代码停止在UserForm2.Show
/ li>
- 您正在创建一个名为
Label
的对象,然后使用
theLabel
然后,您需要增加三个标签的位置,以避免重叠(我使用<$ c $
Sub addLabel()
UserForm2.Show vbModeless
Dim theLabel As Object
Dim labelCounter As Long
对于labelCounter = 1至3
设置Label = UserForm2.Controls.Add(Forms.Label.1,测试& labelCounter,True)
使用TheLabel
.Caption =Test& labelCounter
.Left = 10
.Width = 50
.Top = 10 * labelCounter
结束
下一个
End Sub
I'm trying to dynamically add buttons to the userform, but the userform just comes up blank. Ive simplified the essence of the code as much as possible for error checking (not that it's helped me)
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
Is there any way of checking if the buttons have been added but are invisible? Or why they are not being added. Any help greatly appreciated.
解决方案A few things:
- You need to show your UserForm as
vbModeless
- else the code stops onUserForm2.Show
- You are creating an object called
Label
then usingWith
ontheLabel
You will then need to increment the position of your three labels to avoid overlap (which I have done using
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
这篇关于动态添加标签到用户窗体=空白用户窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文