gpt4 book ai didi

vba - 在 Word VBA 中使用 Application.Run 传递参数

转载 作者:行者123 更新时间:2023-12-02 01:45:16 25 4
gpt4 key购买 nike

我在启动目录中的 Word 插件 (.dotm) 中定义了以下两个 Sub

Public Sub SayHi1()
MsgBox "Hi......."
End Sub

Public Sub SayHi2(ByVal n As String)
MsgBox "Hi " & n
End Sub

然后我可以从一个新文档中调用 1st Sub 而无需参数,如下所示:

Sub AppRun_AddIn_NoArg()
Application.Run "MyProject.Module1.SayHi1"
End Sub

但是当我尝试运行带参数的第二个 Sub 时,我收到错误提示“对象不支持此属性或方法”

Sub AppRun_AddIn_WithArg()
Application.Run "MyProject.Module1.SayHi2", "Tejas"
End Sub

错误信息: enter image description here

最佳答案

这似乎是 Word 长期存在的问题。

作为KB190235 suggests :

Cause:
You have included a template name as part of the Macroname argument string.

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.

关于vba - 在 Word VBA 中使用 Application.Run 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26063986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com