Passing Argument with Application.Run in Word VBA

随声附和 提交于 2019-12-18 08:55:27

问题


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

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

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

Error Message:


回答1:


This appears to be long-standing problem with Word.

As 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.



来源:https://stackoverflow.com/questions/26063986/passing-argument-with-application-run-in-word-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!