Re: Dynamically register (and unregister) functions

716 views
Skip to first unread message

Govert van Drimmelen

unread,
Dec 19, 2012, 6:19:41 AM12/19/12
to Excel-DNA
Hi Kevin,

Cool - that's an improvement to what I had in Excel-DNA before, and
I've incorporated your changes in the source.

Notice that the name is still not entirely removed - if you type it
into the Alt+F8 macro dialog the "Run" button is incorrectly enabled.
This is because your name is now registered as a macro (that final '2'
parameter to xlfRegister).

But because the name no longer refers to a function, it returns #NAME?
to the sheet, which is pretty cool.

Thanks for posting back.

Regards,
Govert



On Dec 19, 12:25 pm, kh <kevinhec...@hotmail.com> wrote:
> Ok, I got the parameters wrong when reregistering as hidden. This version
> correctly returns "#NAME?" after function deregistration. I'm not sure all
> steps are neccessary; happy to get some feedback on this:
>
> private static void UnregisterFunction(string name)
> {
> // get the path to the XLL
> var xllName = XlCall.Excel(XlCall.xlGetName);
>
> // get the registered ID for this function and unregister
> var regId = XlCall.Excel(XlCall.xlfEvaluate, name);
> XlCall.Excel(XlCall.xlfSetName, name);
> XlCall.Excel(XlCall.xlfUnregister, regId);
>
> // reregister the function as hidden and then unregister (clears the
> function wizard)
> var reregId = XlCall.Excel(XlCall.xlfRegister, xllName, "xlAutoRemove",
> "I", name, ExcelMissing.Value, 2);
> XlCall.Excel(XlCall.xlfSetName, name);
> XlCall.Excel(XlCall.xlfUnregister, reregId);
>
>
>
>
>
>
>
> }
Reply all
Reply to author
Forward
Message has been deleted
0 new messages