Excel VBA 中的重复用户表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16817764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 15:42:34  来源:igfitidea点击:

Duplicate User Form in Excel VBA

vbaexcel-vbaexcel

提问by Kartik Anand

I want to duplicate form in excel vba, this is necessary because I have applied some formatting to the form and now want all my forms to have the same formatting.

我想在 excel vba 中复制表单,这是必要的,因为我已经对表单应用了一些格式,现在希望我的所有表单都具有相同的格式。

In this way I'll have to only change the "names" of command button in each form and nothing else.

通过这种方式,我只需要更改每个表单中命令按钮的“名称”,而无需更改其他任何内容。

I tried exporting the form and then importing it, but it gives an error saying "The name is already in use"

我尝试导出表单然后导入它,但它给出了一个错误,提示“名称已被使用”

Any help would be appreciated.

任何帮助,将不胜感激。

回答by

Temporarily change the form name, export it, change the name back, then import the UserForm file. That way they do not match.

临时更改表单名称,将其导出,将名称改回,然后导入 UserForm 文件。这样他们就不匹配了。

回答by Stax

Another method:
With your desired workbook open...
Create a new workbook (Ctrl+N) (by default called Book1) then
within the VBA Project window (Ctrl+R),
drag the form you want, and
drop it onto the new workbook VBAProject(Book1). (a small "plus" under the cursor indicates you're doing it right.)
Now Doubleclick the form you just created. (You may need to click the "plus" in front of the Forms folder to display it) and then
in the Properties window (F4) change the "Name" to something unique.
Now back in the VBA Project window
drag and drop this new form back to your original VBAProject.
Done.

另一种方法:
打开所需的工作簿...
创建一个新工作簿 (Ctrl+N)(默认称为 Book1),然后
在 VBA 项目窗口 (Ctrl+R) 中,
拖动所需的表单,然后
将其放到新的工作簿 VBAProject(Book1)。(光标下的小“加号”表示您做对了。)
现在双击您刚刚创建的表单。(您可能需要单击 Forms 文件夹前面的“加号”以显示它)然后
在“属性”窗口 (F4) 中将“名称”更改为唯一的名称。
现在回到 VBA 项目窗口
,将这个新表单拖放到原始VBA 项目中。
完毕。

For multiple forms repeat the last 2 steps.

对于多个表格,重复最后 2 个步骤。