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

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

问题描述

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

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.

要在不打开 VBE 的情况下获取 ActiveCodepane 对象的句柄,是通过激活 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.ActiveCodePane.CodeModule 在 VBE(代码窗口)未打开时不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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