Passing an argument with Application.Run in Word VBA
I have the following two Subs defined in my Word Addin (.dotm) which I placed in the 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 doc, I can call 1st Sub with no arguments like below:
Sub AppRun_AddIn_NoArg()
Application.Run "MyProject.Module1.SayHi1"
End Sub
But when I try to run the second Sub with an argument, I get the error "Object does not support this property or method"
Sub AppRun_AddIn_WithArg()
Application.Run "MyProject.Module1.SayHi2", "Tejas"
End Sub
Error message:
+3
source to share
1 answer
This seems to be a long-standing problem with Word.
How KB190235 suggests :
Cause:
You included the template name in the Macroname argument string.Resolution:
Remove the template name from the Macroname argument.Workaround:
To avoid naming conflicts between referenced projects, give your procedures unique names so you can call the procedure without specifying a project or module.
+2
source to share