PC Review


Reply
Thread Tools Rate Thread

Conditional Format issue

 
 
Sriram Krish
Guest
Posts: n/a
 
      17th Aug 2009
I have an Excel Add-In for Office 2007. In the application, I have a need to
color the entire row or column based on application created named ranges. I
tried to use Range.Interior.Color to highlight rows or columns for which the
user created named ranges from the application. However, the issue is I have
no way to restore the color the user previously had.

So, I decided to use conditional formating. I union all ranges for which
named ranges are created by the user using the add-in. Then I create
conditional formating for that range with a simple expression "=TRUE" and
then set the interior color in the conditional format. Works great - does not
impact the cell format user has.

Excel.FormatCondition formatCondition = mappedRange.FormatConditions.Add(
XlFormatConditionType.xlExpression,
XlFormatConditionOperator.xlEqual,
"=TRUE",
missing,
missing,
missing,
missing,
missing) as FormatCondition;
if (formatCondition != null) {
formatCondition.StopIfTrue = false;
formatCondition.Priority = 1;
formatCondition.Interior.ColorIndex = 37;
}

I have a highlight toggle button in the Add-In ribbon, which basically
creates or delete the conditional format. In the Add-in a member variable
persists the FormatCondition object that was created. The conditional format
object will be deleted when user turn off highlight toggle button. Works fine
in most cases, but found an issue.

The issue is when user had created conditional format outside of the add-in.
The user creates a named range using the application add-in. Set the
highlight on from the ribbon. Later, user creates their own conditional
format (2D color scale) such that it intersect the range used by the
highlight. Now, when user try to remove the highlight, the
formatCondition.Delete() raises an exception. When I looked into it, the
member variable that had the reference to the formatCondition that created is
no more a single item instead it represents a collection. So, I tried to do
something like formatCondition.AppliesTo.FormatConditions to loop around all
the condition and delete the one I created using the expression test "=TRUE".
While I am looping thru, I first hit up on the one user created which is
color scale condition, so I tried to access the formatCondition.Type == 2 and
right there it raises expection. The reason I found was that the
formatCondition.Type is not accessible for the user created one.

My question to you is how can I delete the format condition that I
programmtically created without impacting the user created format conditions.

Your help on this will be much appreciated.
--
Sriram.K
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional format issue Mike Busch Microsoft Excel Misc 3 29th Nov 2008 05:38 PM
Conditional format issue Patrick C. Simonds Microsoft Excel Worksheet Functions 8 17th Jan 2008 05:37 PM
Conditional Format issue Patrick C. Simonds Microsoft Excel Misc 5 1st Aug 2007 09:26 PM
Conditional Format Issue =?Utf-8?B?RGVhbiBG?= Microsoft Excel Worksheet Functions 8 8th Jun 2006 09:48 AM
Conditional Format Issue =?Utf-8?B?RGFya2RyZXc=?= Microsoft Excel Worksheet Functions 3 13th Apr 2006 04:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:28 AM.