title: C# converting a VBA macro to C# with custom RGB color
body: <p>In converting a VBA macro to a plugin coded in C#, I have run into the following impasse.</p>
  
  <p>The original VBA code is:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Selection.Font.Name = "Times New Roman"
  Selection.Font.Size = 14
  Selection.Font.Bold = True
  Selection.Font.BoldBi = True
  Selection.Shading.Texture = wdTextureNone
  Selection.Shading.ForegroundPatternColor = wdColorAutomatic
  Selection.Shading.BackgroundPatternColor = RGB(173, 216, 230)
  </code></pre>
  
  <p>Converted to C# with the <code>Office.Interop</code> namespace:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.Office;
  using Microsoft.Office.Interop;
  using Word = Microsoft.Office.Interop.Word;
  
  Word.Document oWordDoc = new Word.Document();
  var Selection = oWordDoc.ActiveWindow.Selection;
  
  Selection.Font.Name = "Times New Roman";
  Selection.Font.Size = 14;
  Selection.Shading.Texture = Word.WdTextureIndex.wdTextureNone;
  Selection.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic;
  Selection.Shading.BackgroundPatternColor = Word.ColorFormat.RGB(173, 216, 230);
  </code></pre>
  
  <p>This code won't compile as the <code>RGB</code> is not a Method. I am trying to figure out how to do this with using the available methods, but no luck so far.</p>
  
  <p>I would appreciate any advice on this or any description that would explain the conversion.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Actually, it looks like the following works:</p>
  
  <pre><code>Color mycolor = Color.FromArgb(173, 216, 230);
  Selection.Shading.BackgroundPatternColor = (Word.WdColor)(mycolor.R + 0x100 * mycolor.G + 0x10000 * mycolor.B);
  </code></pre>
  
  <p><a href="https://stackoverflow.com/q/15789429/6201755">This question</a> uses the same approach. But it still looks too complex...</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>With the suggestions below this seems to be the smoothest approach:</p>
  
  <pre><code>Selection.Shading.BackgroundPatternColor = RGB(172,216,230);
  
  private Word.WdColor RGB(int p1, int p2, int p3)
  {
      return (Word.WdColor)p1 + (0x100 * p2) + (0x10000 * p3);
  }
  </code></pre>