简体   繁体   中英

Creating a dynamic form in Excel Vba

I need to create a form in 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.

x can potentially change each time the macro runs. 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 .

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM