如何将.bas vba模块文件内容(变量)集成/链接到vba项目中? [英] How to integrate/link the .bas vba module file contents (variables) into the vba project?

查看:216
本文介绍了如何将.bas vba模块文件内容(变量)集成/链接到vba项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有2个宏-例如M1和M2.

We have 2 macros - say M1 and M2.

M1宏正常工作.

M2宏未按预期运行(没有编译/运行时错误),其原因是此宏M2中缺少1个文件.说F1.bas.该文件具有以下内容.代码:

The M2 macro is not working as expected (there are no compile/run-time errors) and the reason for this is that 1 file is missing in this macro M2. Say F1.bas. This file has the foll. code:

Public Const REG_SZ As Long = 1

宏中的其他文件引用此REG_SZ.在宏M1上,如果我右键单击其他文件中的REG_SZ,然后单击定义",则将我带到此行的F1.bas文件中.

The other files in the macro refer to this REG_SZ. On Macro M1 if I right click on the REG_SZ in the other files and click on Definition, then it takes me to the F1.bas file on this line.

但是,在M2上,尽管我已经导入了F1.bas文件并编译了代码;如果我右键单击其他文件中的REG_SZ,然后单击定义",则会显示一个弹出窗口:无法识别光标下的标识符".

However, on the M2 although I have imported the F1.bas file, and compiled the code; If I right click on the REG_SZ in the other files and click on Definition, then it gives an popup that says: "Identifier under cursor is not recognized".

我的理解是,模块文件中的任何公共变量都应该可以全局访问.建立链接我缺少什么,导入模块文件时我们还需要做其他事情吗?

My understanding is that any public variable in the module file should be globally accessible. Is there something that I am missing to establish the link, do we need to do something else when importing a module file?

推荐答案

我可以建议不要导入F1.bas,而是在M1/M2旁边创建一个新模块并复制F1的内容.

May i suggest that instead of importing F1.bas, create a new module next to M1/M2 and copy contents of F1.

我能够重现您的问题,编辑器似乎对复制内容(而不只是导入)进行了不同的处理.至于原因...我帮不上忙.

I was able to reproduce your problem, and copying the contents instead of just importing seems to be processed differently by the editor. As for the reasons why... I can't help.

进一步的测试表明,对变量Public Const REG_SZ As Long = 1进行注释并取消注释,会迫使编辑器再次(从导入的文件中)识别它.

Further testing shows that commenting your variable Public Const REG_SZ As Long = 1 and uncommenting it, forces the editor to recognise it again (from the imported file).

希望这会有所帮助.

这篇关于如何将.bas vba模块文件内容(变量)集成/链接到vba项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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