Calling macro with argument from commandbarbutton is posible?

Feb 26, 2014 at 1:16 AM
Edited Feb 26, 2014 at 2:19 AM
hi.

I want to create an contextual menu automaticaly using reflexion to obtain the value name and description propery of ExcelFunctionAttribute defined in methods and i want use an unique
macro handler. The handler have to insert in the active cell the function name and then display the formula wizard.

i have this code :

//Obtener el menu contextual de excel
            var _barras = ExcelCommandBarUtil.GetCommandBars();
            var _menuCeldas = _barras["Cell"];
            //Crear nuestro sub menu contextual
            _menuContextual = _menuCeldas.Controls.AddPopup("myContext_Menu", 1);
            _menuContextual.Caption = "My Menu";
//this return the value of property name and description of ExcelFunctionAttribute from methods, using reflexion
            var _funciones = myFunctions.ObtenerFuncionesExcel();
//for each function create a item menu
            foreach(var _funcion in _funciones)
            {
                //Agregar los elementos de nuestro menu
                var _itemMenu = _menuContextual.Controls.AddButton(  _funcion.Name);
                _itemMenu.Caption = _funcion.Codigo.ToUpper();
                _itemMenu.Style = MsoButtonStyle.msoButtonCaption;
                _itemMenu.TooltipText = _funcion.Descripcion;
//here i try to call the macro with parameter functionname
                   _itemMenu.OnAction = "ProcesaFuncionExcel(" + _funcion.Name + ")";
 }

and ProcesaFuncionExcel is:

public static void ProcesaFuncionExcel(string FunctionName)
    {
            MessageBox.Show(FunctionName.ToString());
//here i want to put the function name in the active cell and then display the formula wizard
    }

When run the code and select an item menu, the FunctionName parameter get the function name value and all works fine first time. The problem is the macro run twice an then raise an error if parameter is string, if i try using an int parameter only run twice without error.

is this an error or is not supported to do?

sorry my bad english.