简体   繁体   English

如何在excel vba中卸载多个用户表单?

[英]How do I unload multiple userforms in excel vba?

I have quite a few userforms in an excel workbook. 我在Excel工作簿中有很多用户表单。 As the user moves between the forms, they are hidden. 当用户在表单之间移动时,它们将被隐藏。 What code can I use to unload all the userforms in one shot? 我可以使用哪些代码一次性卸载所有用户表单?

Private Sub CommandButton3_Click()
Unload UserForm15
Unload UserForm14
Unload UserForm13 
Unload UserForm12
Unload UserForm11
Unload UserForm10
Unload UserForm9 
Unload UserForm8
Unload UserForm7
Unload UserForm6
Unload UserForm5
Unload UserForm4
Unload userform3
Unload UserForm2
Unload UserForm1
End Sub

Is there a shorter code to do this, or have I answered my own question? 有没有更短的代码来做到这一点,还是我回答了我自己的问题?

Forms can be cycled through like other objects 表单可以像其他对象一样循环

Sub testIt2()
    Dim i As Long
    For i = VBA.UserForms.Count - 1 To 0 Step -1
        Unload VBA.UserForms(i)
    Next i
End Sub

Not tested 没有测试过

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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