I have an Excel AddIn. I add 2 context menu items in cell's context menu.
When you right click a cell, based on the formula of the cell, one context menu item will be disabled.
I put code for this in sheetSelectionChangeEvent
This works fine in Excel 2003, 2007 and 2010 but it does not work in Excel 2013.
Below is the code:
private void ApplicationSheetSelectionChange(COMObject sh, Range target)
{
DisableMenubarsButtonsWRibbon(XLApp.Selection as Range);
}
public void DisableMenubarsButtonsWRibbon(Range rng)
{
var formula = rng.Formula as string;
if(formula is function1)
{
_contextMenuItem1.Enabled = true;
_contextMenuItem2.Enabled = false;
}
else if(formula is function2)
{
_contextMenuItem1.Enabled = false;
_contextMenuItem2.Enabled = true;
}
else
{
_contextMenuItem1.Enabled = true;
_contextMenuItem2.Enabled = true;
}
}