System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the
target of an invocation.
Source=mscorlib
StackTrace:
at
System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[]
namedParameters)
at System.RuntimeType.InvokeMember(String
name, BindingFlags bindingFlags, Binder binder, Object target, Object[]
providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParams)
at System.Type.InvokeMember(String name,
BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
at ExcelNGN.Main.MyMethod2(IRibbonControl
control) in H:\ExcelNGN\ExcelNGN\Main.cs:line 48
Inner Exception 1:
COMException: Type
mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
namespace ExcelNGN
{
[ComVisible(true)]
public class Main : ExcelRibbon
{
public override string GetCustomUI(string RibbonID)
{
return @"
<ribbon>
<tabs>
<tab id='tab1' label='MyTab'>
<group id='group1' label='Pass Data'>
<button id='Button1' label='Button1' onAction='MyMethod1'/>
<button id='Button2' label='Button2' onAction='MyMethod2'/>
<button id='HideMe1' label='Hide Me1' visible='false' onAction='RunTagMacro' tag='MyMacro1'/>
<button id='HideMe2' label='Hide Me2' visible='false' onAction='RunTagMacro' tag='MyMacro2'/> </group >
</tab>
</tabs>
</ribbon>
</customUI>";
}
public void MyMethod1(IRibbonControl control)
{
MessageBox.Show("MyMethod1 - triggered");
Excel.Application xlapp = (Excel.Application)ExcelDnaUtil.Application;
xlapp.GetType().InvokeMember("Run", BindingFlags.InvokeMethod,
null, xlapp, new object[] { "MyMacro1", "MyParm" });
}
public static void MyMacro1(string arg1)
{
MessageBox.Show(arg1);
}
public void MyMethod2(IRibbonControl control)
{
MessageBox.Show("MyMethod2 - triggered");
Mapper xclMapper = new Mapper();
Excel.Application xlapp = (Excel.Application)ExcelDnaUtil.Application;
xlapp.GetType().InvokeMember("Run", BindingFlags.InvokeMethod,
null, xlapp, new object[] { "MyMacro2", xclMapper });
}
public static void MyMacro2(Mapper arg1)
{
Mapper.RowModel parm1 = arg1.RowModels[1];
MessageBox.Show(parm1.UserLabel);
}
}
}