Naju Mancheril
unread,Oct 11, 2012, 10:04:31 AM10/11/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to exce...@googlegroups.com
Francois,
The addin will definitely let you define macros which take params, but I don't think it is possible to wire them up (with fixed params) to a menu item.
Is that the goal? If so, then I think the easiest solution is to define a "wrapper macro" which takes no params and calls the other macro with ExcelDna's QueueAsMacro functionality. This will give Test full access to the workbook.
In this example, "TestWithMenu" is calling Test with 10 and 15. In fact, you don't even need to export Test as a macro to make this work. ExcelDna is calling it as a .NET function.
[ExcelCommand(Name="TestWithMenu")]
public static void TestWithMenu() {
ExcelAsyncUtil.QueueAsMacro(() => Test(10, 15));
}
//[ExcelCommand(Name="Test")] // don't need to make this a macro, but we can
public static void Test(int x, int y) {
XlCall.Excel(XlCall.xlcAlert, String.Format("Got {0}, {1}", x, y));
var refB1=new ExcelReference(0, 0, 0, 0, "Sheet1");
refB1.SetValue("Set value!");
}
I think the situation will be slightly more complicated if Test (the parameterized macro) is not defined in your .NET addin. For example, it it's exposed by a VBA addin or some other .NET addin, then you'll need to call it by name. Please post back if that is what you're trying to do.