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");