You could check whether the user is editing inside your ribbon macros by using the PenHelper API:
and then code like this:
// The call to LPenHelper will cause an AccessViolation after Excel starts shutting down.
// .NET40: If this library is recompiled to target .NET 4+, we need to add an attribute to indicate that this exception
// (which might indicate corrupted state) should be handled in our code.
[HandleProcessCorruptedStateExceptions]
static int CallPenHelper(int wCode, ref XlCall.FmlaInfo fmlaInfo)
{
try
{
// (If Excel is shutting down, we see an Access Violation here, reading at 0x00000018.)
return XlCall.LPenHelper(XlCall.xlGetFmlaInfo, ref fmlaInfo);
}
catch (AccessViolationException ave)
{
throw new InvalidOperationException("LPenHelper call failed. Excel is shutting down.", ave);
}
}
static bool IsInFormulaEditMode()
{
// check edit state directly
var fmlaInfo = new XlCall.FmlaInfo();
// If Excel is shutting down, CallPenHelper will throw an InvalidOperationException.
var result = CallPenHelper(XlCall.xlGetFmlaInfo, ref fmlaInfo);
if (result == 0)
{
// Succeeded
return fmlaInfo.wPointMode != XlCall.xlModeReady;
}
return false; // We don't really know...
}
-Govert
________________________________________
From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Andrew Lockhart [andrewl...@gmail.com]
Sent: 31 August 2017 07:59 PM
To: Excel-DNA
Subject: [ExcelDna] Disabling the Ribbon when editing in Formula Bar
Hi,
Any suggestions appreciated.
Regards
--
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 post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.