没有明确实例化的VBA用户表单 [英] VBA Userforms used with no explicit instantiation

查看:61
本文介绍了没有明确实例化的VBA用户表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为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:

http://books.google.co.uk/books?id=VnegO0pMYlIC&pg=PA379&lpg=PA379&dq=自动+实例化++用户形式+ in + vba& source = bl& ots = DvHFJkO9Pz& sig = ZiQwsbmqd39kZrwO_joMxNBcwnI& hl = zh-CN& sa = X& ei = _- sWU4-gAZSShQf39oDoAg& ved = 0CEgQ6AEwAg#v = in%20%f %% in =%错误

这篇关于没有明确实例化的VBA用户表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆