Koluns81

Hello,

Im trying to write a method that when you click the button i created in my custom ribbon, calls a method that runs a macro from another file somewhere on the ActiveDocument.

So far i have this method below which i have put together from various different hints on the web. control.Tag holds the name of the file i wish to call that has the macro inside it, that i want to apply to the current document.

But good.run(template) keeps throwing "No overload for method 'Run' takes '1' arguments" I have not been able to find a comprehendible explanation of this error.

public void RunMacroProg(IRibbonControl control)

{

Word.Application good = new Word.Application();

Word.Document bad = good.ActiveDocument;

Object template = myMacroLocation + control.Tag;

good.Run(template);



Re: Visual Studio Tools for Office Run an External Macro in a xxxx.dot file from the Office Ribbon on the current ActiveDocument

Cindy Meister

If you read the Help file for the Application.Run method carefully, you'll see that

1. It requires a STRING value as an argument (not a Template object)

2. This value consists primarily of the macro NAME

3. possibly qualified by the name of the module in which it's located, possibly also qualified by the file path

4. There are another 20 some arguments you have to specifiy (as ref missing). VB languages support optional parameters, C# does not. Here's a code snippet Apurva Sinha posted some time ago:

Word.Range rng = this.Application.Selection.Range;

object tempRng = (object)rng;

object retVal = this.Application.Run("MyMacro", ref tempRng, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);