3

I have a VB6 application that needs to call a Word 2010 VBA routine and supply a string parameter. The VBA routine is in an Addin that is enabled with the open document.

According to the MSDN reference (http://msdn.microsoft.com/en-us/library/ff838935.aspx) I should be able to supply that parameter after the macro name, in order.

My code calling the routine looks like so:

sMacro = "Link.Functions.UpdateFootnote"
sParam = "Footnote Text"
DocApp.Run sMacro, sParam

'I've also tried
DocApp.Run MacroName:=sMacro, varg1:=sParam
'and
DocApp.Run "Link.Functions.UpdateFootnote","Footnote Text"

In each case this yields run-time error 438, "Object doesn't support this property or method."

DocApp.Run "Link.Functions.UpdateFootnote, Footnote text"

This one gives Run-time error -2147352573(80020003) "Unable to run the specified macro"

As a check, I have a 2nd parameterless macro (that then calls the original macro) and it works fine.

DocApp.Run "Link.Functions.UpdateFootnoteTest"

What am I getting wrong here?

Bashzilla
  • 51
  • 1
  • 7
  • This is only a guess, but is it related to spaces in the parameter? – Vicky Nov 04 '11 at 21:04
  • Your first 3 methods work for me as long as I don't include the project name (just using modulename.macroname and the one parameter) Is this code in the same document as the macro you're trying to call? – Tim Williams Nov 04 '11 at 23:13
  • Vicky, I thought of that and tried it without spaces. No luck. – Bashzilla Nov 07 '11 at 14:29
  • Tim, you win! I removed the "Link." from the call and it worked on the first try. Very odd that the parameter-less function would work. – Bashzilla Nov 07 '11 at 14:35

1 Answers1

1

Word is fussy about the ActiveDocument when it comes to using Application.Run. If the function/procedure is in another document (other than the main document's template) that is referenced by the first document, it is sometimes necessary to activate the referenced document first.

Even with the document activated, it is not possible to qualify the function name with the project name. The best you can do is use the module name

Link.ThisDocument.Activate
Application.Run "Functions.Foo", "FOO"
ThunderFrame
  • 9,352
  • 2
  • 29
  • 60