title: Range.Interior.Color Different Between Excel 2007 and Later
body: <p>I'm seeing that Range.Interior.Color returns different numbers for the same color in some cases, depending on whether it is running in Excel 2007, or Excel 2010 or 2013.</p>
  
  <p>Is that expected?? I'm surprised.</p>
  
  <p>Range.Interior.Color is the background color ("Fill Color") of the cell. In the Immediate pane, you can read it like this:</p>
  
  <p>?ActiveCell.Interior.Color</p>
  
  <p>And set it like this:</p>
  
  <p>ActiveCell.Interior.Color = 10921638</p>
  
  <p>Examples:</p>
  
  <p>Example 1:</p>
  
  <p>(these are the same color though their Range.Interior.Color are different.)</p>
  
  <ul>
  <li>Excel 2007:       10855845</li>
  <li>Excel 2010/2013:  10921638</li>
  </ul>
  
  <p>Example 2:</p>
  
  <ul>
  <li>Excel 2007:       14922893</li>
  <li>Excel 2010/2013:  14857357</li>
  </ul>
  
  <p>Example 3:</p>
  
  <ul>
  <li>Excel 2007:       14211288</li>
  <li>Excel 2010/2013:  14277081</li>
  </ul>
  
  <p>Any suggestions? For now, I'm using conditional compliling to set constants for one number or the other depending on VBA constant VBA7, which returns True for Excel 2010 or later and False for Excel 2007 and earlier:</p>
  
  <pre><code>#If VBA7 Then
      'Excel 2010 or later:
      Const NO_SHADING_COLOR As Long = 16777215
      Const MAIN_HEADER_COLOR As Long = 10921638 'dark gray [in xl2007 s/b 10855845]
      Const SUB_HEADER_COLOR As Long = 14857357 'light blue [in xl2007 s/b 14922893]
      Const SUBSUB_HEADER_COLOR As Long = 14277081 'medium gray [in xl2007 s/b 14211288]
  #Else
      'Excel 2007 or earlier:
      Const NO_SHADING_COLOR As Long = 16777215
      Const MAIN_HEADER_COLOR As Long = 10855845 'dark gray
      Const SUB_HEADER_COLOR As Long = 14922893 'light blue
      Const SUBSUB_HEADER_COLOR As Long = 14211288 'medium gray
  #End If
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>Yes, I understand that RGB can be used intead of Range.Interior.Color, and that RGB numbers can be extracted from Range.Interior.Color. But we can do that all day long and still get different sets of RGB numbers depending on Excel version, which effectively takes us back to the original problem.</p>
  
  <p>For any given Range.Interior.Color number, yes it is equivalent to a certain set of RGB numbers. But the point is that depending on Excel version, in some cases you get different Range.Interior.Color numbers for the very same cell without changing the cell's color. If you extract that number to RGB numbers, then you just have different sets of RGB numbers depending on Excel version, which is no better than having the different Range.Interior.Color numbers depending on version.</p>
  
  <p>These cell colors are being set by the user, using Excel's user interface for setting the cell's "Fill Color". The VBA code in this proejct does not set the colors. The VBA code only GETS the colors, and branches according to the color found in the cell being processed.</p>
  
  <p>Aside from obvious exceptions like Application.Version, it isn't normal for object properties to randomly change like this from version to version. Consistency of object properties between versions is an important part of what allows VBA code to work across different versions. If it were not so, we'd have to conditional-compile virtually all our Excel VBA code.</p>