[英]Creating a dynamic form in Excel Vba
I need to create a form in Excel;我需要在 Excel 中创建一个表单; the size and elements of which depend on an array that I have populated in a macro.
其大小和元素取决于我在宏中填充的数组。
So, basically, what I have is an array called Activities(x)
with x
elements.所以,基本上,我拥有的是一个名为
Activities(x)
的数组,其中包含x
元素。
x
can potentially change each time the macro runs.每次运行宏时,
x
都有可能发生变化。 I need to present this list with a checkbox next to each one that will result in a new array called ActivitiesNew(y)
where y
is ( obviously ) smaller than x
.我需要在每个列表旁边显示一个复选框,这将产生一个名为
ActivitiesNew(y)
的新数组,其中y
(显然)小于x
。
I have no idea how to play with the userForm size ( so that I can incorporate all the elements that should be shown ) or with the caption of each checkbox so that the correct text is displayed.我不知道如何使用 userForm 大小(以便我可以合并应该显示的所有元素)或每个复选框的标题,以便显示正确的文本。
You can manipulate the size of the UserForm like this :您可以像这样操作用户窗体的大小:
'Suppose UserForm is the name of your element
With UserForm
.Height
.Width
End With
And for the checkbox :对于复选框:
'Suppose CheckBox is the name of your element
With CheckBox
.Left 'Beginning of the checkbox compared to the left side of the UserForm
.Width
.Top 'Beginning of the checkbox compared to the top of the UserForm
.Height
.Caption 'Change the displayed text
End With
If changing the position and size of these elements is the only thing you want to do, this should be enough.如果改变这些元素的位置和大小是你唯一想做的事情,这应该就足够了。
You can also create a CheckBox when a macro is running using VBA:您还可以在使用 VBA 运行宏时创建 CheckBox:
Set TheCheckBox = UserForm.Controls.Add("Forms.CheckBox.1", Visible = True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.