Custom UI Runtime Error -

156 views
Skip to first unread message

Andrew DeBear

unread,
Aug 15, 2023, 3:12:36 PM8/15/23
to Excel-DNA
I have a UDF that is working as expected.

I am trying to figure out how to call that  UDF from a custom ribbon menu and bring up the normal excel Function Arguments dialog box.

I've tried a few variations of cellActive.value = strFunc, but everything is generating a different runtime error with each attempt.

Any recommendations for how to invoke the UDF in the Function Arguments dialog box? Thanks!

// code from RibbonController.cs
// OPEN EXCEL INSERT FUNCTION DIALOG BOX (blank)

public void OpenDialog(IRibbonControl control)

{

dynamic cellActive = Application.ActiveCell;

cellActive.FunctionWizard();

}

 

// OPEN EXCEL FUNCTION ARGUMENTS DIALOG BOX FOR UDF

public void Func212(IRibbonControl control)

{

strFunc = "=C_RevStr('TAC')";

  dynamic cellActive = Application.ActiveCell;

 

// THIS IS THROWING CUSTOM UI RUNTIME ERROR FROM EXCEL

cellActive.formula = strFunc;

}

function-arguments.png


runtime-error.png

Govert van Drimmelen

unread,
Aug 15, 2023, 3:26:56 PM8/15/23
to exce...@googlegroups.com

--------------------------------------------------
Excel-DNA is now registered on 
GitHub Sponsors.
Every monthly contribution directly funds further development.
--------------------------------------------------

 

Hi Andrew,

 

I think the problem is the single quotes – they won’t work in an Excel formula.

You can try:

 

    string strFunc = "=C_RevStr(\"TAC\")";

 

-Govert

 

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/5f57675b-d155-4db4-bfa5-ba1f63d93a57n%40googlegroups.com.

image001.png
image002.png

Andrew DeBear

unread,
Aug 15, 2023, 4:23:28 PM8/15/23
to Excel-DNA
OK. That wasn't exactly what I was looking for, but it put me on the right track.

This is what I did to get the menu button to open up the arguments dialog box for the specified UDF...

Thanks!

public void Func212(IRibbonControl control)

{

//strFunc = "=C_RevStr(\"TAC\")"; // Excel doesn't recognized single quotation marks

strFunc = "=C_RevStr()";

 

dynamic cellActive = Application.ActiveCell;

 

cellActive.formula = strFunc; // just puts function string in cell

cellActive.FunctionWizard(); // opens up the arguments dialog box for UDF

}


dialog.png
Reply all
Reply to author
Forward
0 new messages