在Excel Vba中创建动态表单

在Excel Vba中创建动态表单,excel,checkbox,vba,Excel,Checkbox,Vba,我需要在Excel中创建一个表单;其大小和元素取决于我在宏中填充的数组 基本上,我有一个叫做Activitiesx的数组,包含x个元素 每次运行宏时,x都可能发生更改。我需要在每个列表旁边显示一个复选框,该复选框将生成一个名为ActivitiesNewy的新数组,其中y明显小于x 我不知道如何使用userForm大小,这样我就可以合并所有应该显示的元素,或者使用每个复选框的标题来显示正确的文本。您可以像这样操作userForm的大小: 'Suppose UserForm is the name

我需要在Excel中创建一个表单;其大小和元素取决于我在宏中填充的数组

基本上,我有一个叫做Activitiesx的数组,包含x个元素

每次运行宏时,x都可能发生更改。我需要在每个列表旁边显示一个复选框,该复选框将生成一个名为ActivitiesNewy的新数组,其中y明显小于x


我不知道如何使用userForm大小,这样我就可以合并所有应该显示的元素,或者使用每个复选框的标题来显示正确的文本。

您可以像这样操作userForm的大小:

'Suppose UserForm is the name of your element
With UserForm
    .Height     
    .Width
End With
对于复选框:

'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
如果您只想更改这些元素的位置和大小,那么这就足够了

也可以在使用VBA运行宏时创建复选框:

Set TheCheckBox = UserForm.Controls.Add("Forms.CheckBox.1", Visible = True)