I can only answer for myself and the below list gives some indication when I use it, i e creating conditional formattings, via code:
- To highlight various groups of data in pivottables, lists and tables. Usually the raw data is retrieved from database(s).
- Creating standalone workbooks and/or templates through code where it’s necessary to highlight data in specific areas.
In general I try to avoid other situations then above as I find it complicated to work, through code, with conditional formatting under other circumstances.
With Excel 2007 we now have several new conditional formats to use. However, the new conditional formats also bring ‘new rules’ for working with them in code. Therefore we need to be aware of it and, of course, know how to work with them.
The following code example shows how we work with one of the old conditional formats, adding a conditional formatting based on an expression, in VSTO:
The most interesting aspect in the above sample is the declaration of the variable p_cfOld as an Excel.FormatCondition’s object.
The following code example shows how we work with one of the new conditional formats, adding a conditional formatting based on the Icon Sets, for Excel 2007 in VSTO:
As the above sample shows, we now use the Icon Set’s object instead of the general FormatCondition’s object. If we should try to use the FormatCondition’s object it would end with an exception.
The new conditional format’s objects seem not to be part of the general FormatCondition’s object. Instead the new conditional formats have their own collections and therefore we need to explicit declare the format type(s) involved for specifik tasks. However, as the above samples show, they seem at least to be part of the range object’s conditional format collection.