在 Word VBA 中使用 Application.Run 传递参数 [英] Passing Argument with Application.Run in Word VBA
问题描述
我在我的 Word Addin (.dotm) 中定义了以下两个 Sub,并将其放入 StartUp 目录
I have the following two Sub defined in my Word Addin (.dotm) which I have put in StartUp directory
Public Sub SayHi1()
MsgBox "Hi......."
End Sub
Public Sub SayHi2(ByVal n As String)
MsgBox "Hi " & n
End Sub
然后从一个新文档中,我可以不带参数地调用 1st Sub,如下所示:
Then from a new document I am able to call 1st Sub without argument as below:
Sub AppRun_AddIn_NoArg()
Application.Run "MyProject.Module1.SayHi1"
End Sub
但是当我尝试使用参数运行第二个 Sub 时,我收到错误消息对象不支持此属性或方法"
But when I try to run the 2nd Sub with argument I get error saying "Object doesn't support this property or method"
Sub AppRun_AddIn_WithArg()
Application.Run "MyProject.Module1.SayHi2", "Tejas"
End Sub
错误信息:
推荐答案
这似乎是 Word 的长期问题.
This appears to be long-standing problem with Word.
正如 KB190235 建议:
原因:
您已将模板名称作为 Macroname 参数字符串的一部分.
Cause:
You have included a template name as part of the Macroname argument string.
分辨率:
从 Macroname 参数中删除模板名称.
Resolution:
Remove the template name from the Macroname argument.
解决方法:
为避免引用项目之间的命名冲突,请为您的过程指定唯一名称,以便您可以在不指定项目或模块的情况下调用过程.
Workaround:
To avoid naming conflicts among referenced projects, give your procedures unique names, so that you can call a procedure without specifying a project or module.
这篇关于在 Word VBA 中使用 Application.Run 传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!