如何计算隐藏的用户表单 [英] How to count hided userforms
本文介绍了如何计算隐藏的用户表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想计算包含隐藏的用户形式。以下代码只能显示。
Sub CountUfs()
debug.print UserForms.Count
end sub
解决方案
< blockquote>
这是一个计算工作簿中的用户形式的函数:
函数CountUserForms(wbk As Workbook)As long
Dim c As Object
For Each c in wbk.VBProject.VBComponents
if c.Type = 3 Then
CountUserForms = CountUserForms + 1
End if
Next c
结束函数
用法:
Debug.Print CountUserForms(ActiveWorkbook)
或
Debug.Print CountUserForms(工作簿("MyWorkbook.xlsm"))
重要:代码仅在您信任对Visual Basic项目的访问权限时才有效。
- 在Excel中,选择文件>选项。
- 单击信任中心。
- 单击信任中心设置...
- 在左侧导航窗格中选择宏设置。
- 确保勾选了"信任对VBA项目对象模型的访问权限"复选框。
- 单击"确定",然后再次单击"确定"。
Hello everybody,
I want to count userforms including hided ones. The following code can only the showed ones.
Sub CountUfs()
debug.print UserForms.Count
end sub
解决方案
Here is a function that counts userforms in a workbook:
Function CountUserForms(wbk As Workbook) As Long Dim c As Object For Each c In wbk.VBProject.VBComponents If c.Type = 3 Then CountUserForms = CountUserForms + 1 End If Next c End FunctionUsage:
Debug.Print CountUserForms(ActiveWorkbook)
or
Debug.Print CountUserForms(Workbooks("MyWorkbook.xlsm"))
Important: the code will only work if you trust access to the Visual Basic Project.
- In Excel, select File > Options.
- Click Trust Center.
- Click Trust Center Settings...
- Select Macro Settings in the navigation pane on the left.
- Make sure that the check box 'Trust access to the VBA project object model' is ticked.
- Click OK, then click OK again.
这篇关于如何计算隐藏的用户表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文