[dna.ExcelFunction(IsMacroType = true)]
public static DateTime MyTest1()
{
//this works great
dynamic xlApp = dna.ExcelDnaUtil.Application;
xlApp.OnTime(DateTime.Now, "TimedProc1");
return DateTime.Now;
}
[dna.ExcelCommand]
public static void TimedProc1()
{
System.Windows.Forms.MessageBox.Show("TimedProc1");
}
Now, I would really like for the method being called by the timer to have a parameter or two.
This can be achieved in VBA by wrapping the name of the procedure to be called together with the arguments in single quotes. Here's an example:
Public Sub test()
Application.OnTime Now, "'TimedProcVBA 1, 2'"
End Sub
Public Sub TimedProcVBA(ByVal lngValue1 As Long, ByVal lngValue2 As Long)
MsgBox "TimedProcVBA " & CStr(lngValue1) & " " & CStr(lngValue2)
End Sub
Unfortunately, I can't seem to do this in DNA. I've tried a few different combinations (quotes, no quotes etc), with this being the most obvious:
[dna.ExcelFunction(IsMacroType = true)]
public static DateTime MyTest2()
{
//this works great
dynamic xlApp = dna.ExcelDnaUtil.Application;
xlApp.OnTime(DateTime.Now, "'TimedProc2 1, 2'");
return DateTime.Now;
}
[dna.ExcelCommand]
public static void TimedProc2(object myObject1, object myObject2)
{
System.Windows.Forms.MessageBox.Show(string.Format("TimedProc2 {0} {1}",myObject1,myObject2));
}
But I get an error message in Excel saying that it can find the macro TimedProc2 1, 2.
Please would someone tell me the correct syntax to do this?
Thanks,
Colin