使用 VBA 将选项卡添加到 Excel 中的多页表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10524686/
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-11 16:06:05  来源:igfitidea点击:

Using VBA to add tabs to a multipage useform in excel

excelvbaexcel-vbauserformmultipage

提问by Ehudz

I need to find the VBA code to add x number of tabs to a multipage in a userform in excel. I can manually add tabs if I use the visual basic editor, but I want to be able to dynamically add/delete tabs using VBA during runtime.

我需要找到 VBA 代码才能在 excel 的用户表单中向多页添加 x 个选项卡。如果我使用 Visual Basic 编辑器,我可以手动添加选项卡,但我希望能够在运行时使用 VBA 动态添加/删除选项卡。

Thanks

谢谢

采纳答案by Siddharth Rout

The Tabsin a MultiPage1are called Pagesand you can add them using

Tabs一个MultiPage1被称为Pages,您可以使用它们添加

MultiPage1.Pages.Add

You can use the above code in a loop to add pages. Please refer to Excel's inbuilt help for more details

您可以循环使用上述代码来添加页面。有关更多详细信息,请参阅 Excel 的内置帮助

Edit:

编辑

Just saw the 2nd part of the question. To delete, say the 1st page use this

刚刚看到问题的第二部分。要删除,请说第一页使用此

MultiPage1.Pages.Remove (0)

回答by brettdj

You can add/remove them dymanically to the form permanently with

您可以使用以下命令将它们永久地添加/删除到表单中

Sub Test()
Dim vbComp As Object
Dim objCntrl As Control
Set vbComp = ThisWorkbook.VBProject.VBComponents("UserForm1")
Set objCntrl = vbComp.Designer.Controls("MultiPage1")
'add page
objCntrl.Pages.Add
'remove page
objCntrl.Pages.Remove (1)
End Sub