簡體   English   中英

在 Excel Vba 中創建動態表單

[英]Creating a dynamic form in Excel Vba

我需要在 Excel 中創建一個表單; 其大小和元素取決於我在宏中填充的數組。

所以,基本上,我擁有的是一個名為Activities(x)的數組,其中包含x元素。

每次運行宏時, x都有可能發生變化。 我需要在每個列表旁邊顯示一個復選框,這將產生一個名為ActivitiesNew(y)的新數組,其中y顯然)小於x

我不知道如何使用 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 運行宏時創建 CheckBox:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM