当未打开VBE(代码窗口)时,为什么VBE.ActiveCodePane.CodeModule不起作用? [英] Why doesn't VBE.ActiveCodePane.CodeModule work when the VBE (code window) isn't open?

查看:223
本文介绍了当未打开VBE(代码窗口)时,为什么VBE.ActiveCodePane.CodeModule不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个运行以下代码的表单.

Create a form that runs the following code.

MsgBox (VBE.ActiveCodePane.CodeModule)

出现此消息.

现在保存,关闭并重新打开数据库,然后看到以下消息:

Now save, close, and reopen the database, and see this message:

运行时错误'91':对象变量或未设置块变量

Run-time error '91': Object variable or With block variable not set

如果打开Visual Basic编辑器,它将再次运行.即使您关闭了VBE,它仍然可以运行.

If you open the Visual Basic Editor, it runs again. Even if you close the VBE, it still runs.

但是,当您关闭整个应用程序并重新打开它,而使VBE关闭时,您会收到错误消息.

But when you close the whole application and reopen it, leaving the VBE closed, you get the error.

为什么?这是怎么回事?

Why? What's going on here?

推荐答案

您引用活动窗格对象.在激活窗格之前,不会设置该对象.因此,在打开VBE之前,尚未设置对象.关闭VBE后,该对象仍然存在,因此您仍然可以引用它.

You reference the active pane object. The object isn't set until a pane gets activated. So before you open the VBE, the object is not set yet. Once you close the VBE, the object remains, so you can still reference it.

要获得ActiveCodepane对象的句柄而不打开VBE,是通过激活VBComponent,如下所示:

To get a handle to the ActiveCodepane object, without opening the VBE, is by activating a VBComponent, like this:

VBE.ActiveVBProject.VBComponents("Module1").Activate

您可以像这样激活任何VBComponent.

You can activate any VBComponent like this.

这篇关于当未打开VBE(代码窗口)时,为什么VBE.ActiveCodePane.CodeModule不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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