title: Dynamic disable/enable custom context menu in Excel 2013
body: <p>I have an Excel AddIn. I add 2 context menu items in cell's context menu.</p>
  
  <p>When you right click a cell, based on the formula of the cell, one context menu item will be disabled.</p>
  
  <p>I put code for this in <code>sheetSelectionChangeEvent</code></p>
  
  <p>This works fine in Excel 2003, 2007 and 2010 but it does not work in Excel 2013.</p>
  
  <p>Below is the code:</p>
  
  <pre><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;
       }
   }
  </code></pre>