Unregistering Not Working Anymore

464 views
Skip to first unread message

andste

unread,
Jul 19, 2011, 7:38:11 PM7/19/11
to Excel-DNA
In the pas (version 0.28), I have been using the following code to
"unregister" functions after checking certain conditions in AutoOpen()

Private Sub RemoveMe()
Dim myName As String = DirectCast(XlCall.Excel(XlCall.xlGetName),
String)
Dim removeId As Object = XlCall.Excel(XlCall.xlfRegister, myName,
"xlAutoRemove", "I", ExcelMissing.Value, ExcelMissing.Value, 2)
Dim removeResult As Object = XlCall.Excel(XlCall.xlfCall, removeId)
Dim removeUnregister As Object = XlCall.Excel(XlCall.xlfUnregister,
removeId)
End Sub

Now (version 0.29), I have noticed that the above commands do not work
anymore. The conditions in AutoOpen() are checked and recognized
properly, but calling RemoveMe() has no effect: the UDF load anyway.

Rgrds,
Andi

Govert van Drimmelen

unread,
Jul 19, 2011, 8:06:54 PM7/19/11
to Excel-DNA
Hi Andi,

I'm a bit surprised that you say it worked from the AutoOpen in
previous versions.
I'd expect it not to work from AutoOpen at all (but to be OK when
called from a macro later), and can't remember changing anything
relevant.
But perhaps I've forgotten something...

It would help me a lot if you could post a self-contained .dna file
with some function that 'works' (i.e. unregisters making the function
unavailable) under v. 0.28 and does not unregister properly under v.
0.29, (with the AutoOpen and other stuff needed to just run and test
it).
I can then have a closer look on Thursday or over the weekend.

Regards,
Govert

andste

unread,
Jul 20, 2011, 1:41:44 AM7/20/11
to Excel-DNA
Hi Govert,
I did a 0.28 version of the add-in in which I am using the above
RemoveMe() code, and everything works fine. So there is something with
version 0.29.
You might be able to replicate the error with your own code in the
thread "Security check before addin registration" (the code in
RemoveMe() is exactly your code from tha thread). If I find the time,
I will create a self-contained dna file which triggers the error.

Thank you in advance and

Rgrds,
Andi

Govert van Drimmelen

unread,
Jul 20, 2011, 2:51:06 AM7/20/11
to Excel-DNA
Hi Andi,

Ah - thank you for pointing back to that example.
I can now reproduce the difference between 0.28 and 0.29.

I'll dig into it a bit to see what changed...

-Govert

Govert van Drimmelen

unread,
Jul 24, 2011, 12:23:30 PM7/24/11
to Excel-DNA
Hi Andreas,

OK - I've now been able to trace the change in v 0.29 that broke the
unregistering when called from AutoOpen. In the new version I only
really Unregister the functions if an _opened flag has been set, but
this flag is set only after the AutoOpen has finished running. I've
now updated the behaviour in the code so that in the next version the
flag will be set before the AutoOpen is run, but the next version 0.30
won't be available for a while.

For you to move to version 0.29, which I recommend, I suggest the
following workaround. You basically just schedule the RemoveMe macro
to run immediately, using a call to xlcOnTime.
I post some fragments below.

If you need more help getting this to work, please let me know.

Regards,
Govert

public void AutoOpen()
{
DialogResult result = MessageBox.Show("Should the Add-In be
loaded?",
"Add-in check", MessageBoxButtons.YesNo);
if (result == DialogResult.No)
{
double now = (double)XlCall.Excel(XlCall.xlfNow);
XlCall.Excel(XlCall.xlcOnTime, now, "RemoveMe");
}
}
public void AutoClose()
{
}


public static void RemoveMe()
{
string myName = (string)XlCall.Excel(XlCall.xlGetName);
object removeId = XlCall.Excel(XlCall.xlfRegister, myName,
"xlAutoRemove", "I" , ExcelMissing.Value,
ExcelMissing.Value, 2);
object removeResult = XlCall.Excel(XlCall.xlfCall, removeId);
object removeUnregister = XlCall.Excel(XlCall.xlfUnregister,
removeId);
MessageBox.Show("This add-in has been disabled.", "Add-in
check");

andste

unread,
Jul 24, 2011, 2:31:18 PM7/24/11
to Excel-DNA
Govert,
I am fine with a workaround for the time being, no problem.
If I implement your code, I get an error meesage from Excel saying
"Cannot run the macro RemoveMe. The macro may not be available in this
workbook or all macros may be disabled".
If I click OK, the functions are still loaded . Macros are not
diabled, this isn't the issue.
Maybe an additional line of code is needed in order to load the sub
RemoveMe() before it is executed?

Thank you for your assistance.

Rgrds,
Andi

Govert van Drimmelen

unread,
Jul 24, 2011, 2:55:41 PM7/24/11
to Excel-DNA
RemoveMe needs to be 'public static' to be registered as a macro.
In the original example it was a private member on the class
implementing IExcelAddIn.

Could you check what you have?

-Govert

andste

unread,
Jul 24, 2011, 3:16:27 PM7/24/11
to Excel-DNA
Bingo: after setting RemoveMe to 'public static', everything worked
fine. Thanks a lot!!

Rgrds,
Andi

ajwillshire

unread,
Jul 27, 2011, 7:47:21 AM7/27/11
to Excel-DNA
Hi,

This solution seems to work fine for me up until I pack the Xll file.
Then it seems to just skip past the AutoOpen. Any idea why that should
be?

Thanks,
Andrew

ajwillshire

unread,
Jul 27, 2011, 10:09:21 AM7/27/11
to Excel-DNA
Although I just tried again after re-compiling (about the 4th time)
and it did work...

Never mind, I'll come back if I can actually come up with a
reproducible fault.
> > Andi- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages