vba 如何从另一个模板调用全局模板/加载项中的宏函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5227903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I call a macro function in a global template/add-in from another template?
提问by Sam
First, I am a VBA newbie. So please pardon my ignorance.
首先,我是VBA新手。所以请原谅我的无知。
I have a global template that I installed in the Word startup folder.
我在 Word 启动文件夹中安装了一个全局模板。
The global template has some macros that I would like to access. But I can't figure out how to access the macro.
全局模板有一些我想访问的宏。但我不知道如何访问宏。
I tried to use Application.Run
, but that doesn't work (or at least I'm doing it wrong). I keep getting Runtime Error 424.
我尝试使用Application.Run
,但这不起作用(或者至少我做错了)。我不断收到运行时错误 424。
I also tried to use something like Call globaltemplatename.modulename.functionname
but that doesn't work either.
我也尝试使用类似的东西,Call globaltemplatename.modulename.functionname
但这也不起作用。
I also tried to simply call the function but then it says that the function/sub is not defined.
我也尝试简单地调用该函数,但它说该函数/子未定义。
回答by Sam
LOL... um... nvm... I found out why...
大声笑......嗯...... nvm......我发现了为什么......
I didn't create a reference in the template that I was calling from...
我没有在我调用的模板中创建引用...
Well...in case anybody else runs into this problem, you have to open the template (not the global template) and then go to Tools > References in the VB editor. And then check the project name of the global template.
好吧...万一其他人遇到这个问题,您必须打开模板(不是全局模板),然后在 VB 编辑器中转到工具 > 引用。然后检查全局模板的项目名称。
回答by Felix
sTemp = Application.Run ("modulename.functionname")
The entire string is in double quotes.
整个字符串都在双引号中。
Word does not want the templates name - leave it out.
Word 不需要模板名称 - 将其省略。
回答by Tozi T
Even more Word do not let you use more than ModuleName.ProcName. Otherwise a runtime error will be thrown.
甚至更多 Word 不允许您使用ModuleName.ProcName以外的更多内容。否则将抛出运行时错误。