c# - Excel.Interop: AccessViolation exception when one of the parameters referes to another sheet -
i've tried create recordset using excel.interop , exceldna. use list function function wizard dialog. do: 1) write activecell.formular1c1 value of function ("=myfunction()") 2) , tries run function wizard
... cell.formular1c1 = formulastr; if (!(bool)cell.functionwizard()) { ...
function dialog starts , works fine(i can set parameters) when press ok accessviolation error occurs in case if @ least 1 of parameters refers sheet.(if located @ 1 sheet, method works fine). function evaluates after pressing ok button , exception occurs on functionwizard() method. have similar?
---------- update --------------
i made simple dna addin, 1 button.. , error still reproduces: 1) function:
[excelfunction("my test function")] public static string mytestfunction(string param1, string param2) { return "it works!"; }
2) ribbon button code:
public void onbuttonpressed(iribboncontrol control) { application exap = (application)exceldnautil.application; range ac = exap.activecell; ac.formular1c1 = "=mytestfunction()"; if ((bool)ac.functionwizard()) { // } }
so when set parameters sheet , press ok @ function wizard, accessviolation occurs.
found solution. used:
microsoft.office.interop.excel.dialog dialog = app.dialogs.get_item(microsoft.office.interop.excel.xlbuiltindialog.xldialogfunctionwizard); if (!(bool)dialog.show()) {
instead of:
if (!(bool)cell.functionwizard()) {
and works fine.
Comments
Post a Comment