【发布时间】:2016-12-31 02:05:03
【问题描述】:
有人可以指导我如何在 VBA 中动态创建日期选择器控件吗? 这是我想要做的。我有一个宏,它根据最终用户是否希望它可见或不将 TextBox 和 ComboBox 控件动态添加到 VBA 用户窗体中。可见性(以及所有其他控件属性-宽度、高度等)由最终用户控制,方法是根据 Excel 中“主”表中提供的控件名称更新是/否值。
这是我为 TextBox 和 ComboBox 控件所做的
`sub test()
---- some code
Dim txtTextBox As MSForms.TextBox
Dim cmbComboBox As MSForms.ComboBox
If 'some cell in excel ‘Master’ worksheet' = "ComboBox" Then
Set cmbComboBox = UserForm.Controls.Add("Forms.ComboBox.1", 'some cell in excel ‘Master’ worksheet')
cmbComboBox.top = 'some cell in excel ‘Master’ worksheet'
cmbComboBox.left = 'some cell in excel ‘Master’ worksheet'
cmbComboBox.Width = 'some cell in excel ‘Master’ worksheet'
cmbComboBox.height = 'cell in excel ‘Master’ worksheet'
----rest of my code
end sub`
我的问题是,我如何动态添加日期选择器,就像我添加文本框和组合框的方式一样。我使用 Controls.Add 的正确方法是什么?如果是这样,我该怎么做?有人可以帮我解决这个问题! 希望我的问题有意义。
【问题讨论】:
-
你见过This
标签: vba excel dynamic userform