I'm working on an import (from Excel) dialog that uses automation to allow the user to select ranges of cells for import. When the range is selected, I'm using the event sink to catch the event and hilight the first row and first column. I need to have a way to unhilight the previous selection's first row and column. I don't think it's safe to just get the selected range at the time the selection changes, and remember it, such as (psuedocode for brevity and clarity):
OnSelectionChange()
{
if (m_PrevSelection)
UnHilite(m_PrevSelection);
HiliteCurrentSelection();
GetSelectedRange(m_PrevSelection);
}
I'm guessing that just holding onto that range (obtained from _Application::Selection) without releasing it is going to cause all sorts of problems (but maybe I'm wrong). I haven't found a way to copy the range (IRange Copy just copies cell contents from one range to another).
I guess I could take the range's cell addresses and store those, then recreate a range from the when I need to do the unhilighting, but this would seem to me to come up so often I'm wondering if anyone else had a more elegant solution.