问题描述
假设我有一个名为MyUserForm
的用户表单,
Let's say I have a userform called MyUserForm
that I use like
Dim form as MyUserForm
Set form = New MyUserForm
form.SomeVar = "Hi"
form.Show ' Displays "Hi" somewhere on the form
一切都很好,花花公子.但是以下内容,也让我感到奇怪的是,它也起作用:
and all is fine and dandy. But the following, and this is what strikes me as odd, works as well:
MyUserForm.SomeVar = "Hi"
MyUserForm.Show
看起来好像有一些隐式声明的 object MyUserForm
,其类型恰好是 class MyUserForm
! VBA在这里到底在做什么?管理这个奇怪习语的规则是什么?谢谢
which looks like there's some implicitly declared object MyUserForm
whose type is precisely the class MyUserForm
! What is VBA really doing here? What are the rules governing this strange idiom? Thank you
推荐答案
这是用户窗体的默认实例.您应该尝试避免这种情况,因为您将无法完全控制实例化和销毁.看看这个:
This is the default instance of the userform. You should try and avoid it, because you won't have full control over instantiation and destruction. Have a look at this:
这篇关于没有明确实例化的VBA用户表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!