From: Christopher Robin on
I've posted this in a few places, but am not getting any traction, so here is
another post. =D

I'm attempting to create a relatively simple Excel Add In. I have the
basics working, but now I'm attempting to iterate through the existing Format
Conditions and show a message box with the AppliesTo range. All I ever get,
sadly, is the _ComObject. In VBA, I could do AppliesTo.Address to see the
range, but that doesn't seem to be available in C# VSTO 2008. I did convert
this add-in to VS2010, and the AppliesTo.Address property has re-appeared,
but now Excel consistently crashes every time.

What I really want to do is fix the Applies To range, after a data refresh,
but this tends to consistently crash Excel. What's odd, though, is that the
code below doesn't crash it immediately, rather I get two message boxes, and
then it crashes. Of course, I'm not saving the work book, so I have no idea,
if the code is really working or not.

At this point, I'm pretty frustrated because there doesn't really seem to be
a lot of documentation, and the method works a couple of times before bombing
Excel and forcing an error report. If anyone can provide some insight and/or
links, I would be forever in your debt.

private void btnUpdateRange_Click(object sender,
RibbonControlEventArgs e)
{
if (curRange.FormatConditions.Count == 0)
{
MessageBox.Show("No Conditional Formats set up in current
sheet", "No Formats", MessageBoxButtons.OK);
}

else
{
foreach (xls.FormatCondition oFc in curRange.FormatConditions)
{
//MessageBox.Show(oFc.AppliesTo.Value2.ToString(),
"Applies to Range", MessageBoxButtons.OK);
oFc.ModifyAppliesToRange(curRange);
}
}
}