title: Specific columns width of a MailItem Table in Outlook using VBA and HTML
body: <p>I copy a table from Excel to an Outlook mailitem.</p>
  <p>I want to set specific columns width to the table in Outlook.</p>
  <p>This is the result of the code.<br />
  <a href="https://i.stack.imgur.com/XZUAS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XZUAS.png" alt="enter image description here" /></a></p>
  <p>In Outlook I manually Autofit contents, then set from column 4 to 8 to 2 cm, column 9 is 2,3 cm and last column (10) is 2,4 cm.<br />
  How can that be done with HTML? I can set a fixed size from column 1 to 3 since it will be always the same.</p>
  <p>I would also like to know how to make listed rows. I tried to use a code, but it didn't work.</p>
  <p>This is the expected result.<br />
  <a href="https://i.stack.imgur.com/0Gsx2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Gsx2.png" alt="enter image description here" /></a></p>
  <p>This is the current code in VBA:</p>
  <pre class="lang-vb prettyprint-override"><code>Function HTMLTabelaEntrada() As String
      Dim EntradaRG As Range, PrimColuna As Range, i As Range, RowRG As Range, j As Range
      Dim Rows As Long, iRow As Long
      Dim NumColuna
      Dim str As String
      Rows = Folha1.ListObjects(1).DataBodyRange.Rows.Count + 1
      Folha1.Activate
      str = &quot;&lt;table&gt;&quot;
      
      Set PrimColuna = Range(Cells(1, eData), Cells(Rows, eData))
      
      For Each i In PrimColuna
      
          str = str &amp; &quot;&lt;tr&gt;&quot;
          iRow = i.row
          Set RowRG = Union(Cells(iRow, eData), Cells(iRow, eeSku), Cells(iRow, eeDescrição), _
            Cells(iRow, eeCaixasCompletas), Cells(iRow, eeCuvetesCaixa), _
            Cells(iRow, eeCuvetesSoltas), Cells(iRow, eeCuvetesTotal), _
            Cells(iRow, eeCaixasEsperadas), Cells(iRow, eeValidade), Cells(iRow, eeNotas))
          For Each j In RowRG
              j.Select
              If i.row = 1 Then
                  str = str &amp; &quot;&lt;th&gt;&quot; &amp; j.Value &amp; &quot;&lt;/th&gt;&quot;
              ElseIf j.column = eData And j.row &lt;&gt; 1 Then
                  str = str &amp; &quot;&lt;td&gt;&quot; &amp; Format(j.Value, &quot;dd/mmm&quot;) &amp; &quot;&lt;/td&gt;&quot;
              ElseIf j.column = eeCuvetesTotal And j.Value = 0 Then
                  str = str &amp; &quot;&lt;td&gt;&quot; &amp; &quot; &quot; &amp; &quot;&lt;/td&gt;&quot;
              ElseIf j.column = eeDescrição And j.row &lt;&gt; 1 Then
                  str = str &amp; &quot;&lt;td style=&quot;&quot; text-align:left&quot;&quot;&gt;&quot; &amp; j.Value &amp; &quot;&lt;/td style&gt;&quot; &amp; &quot;&lt;/td&gt;&quot;
              Else
                  str = str &amp; &quot;&lt;td&gt;&quot; &amp; j.Value &amp; &quot;&lt;/td&gt;&quot;
              End If
          Next j
          str = str &amp; &quot;&lt;/tr&gt;&quot;
      Next i
      str = str &amp; &quot;&lt;/table&gt;&quot;
      HTMLTabelaEntrada = str
  End Function
      
       
  Function HeadHTMLTable()
              
      Dim str As String
                  
      str = &quot;&lt;head&gt;&lt;style&gt;&quot; &amp; vbNewLine
      str = str &amp; &quot;p{font-family:Cambria;font-size:16px}&quot; &amp; vbNewLine
      str = str &amp; &quot;table{table-layout:fixed;font-family:cambria;font-size:16px;border: 1px solid black;border-collapse:collapse;width:75%}&quot; &amp; vbNewLine
      str = str &amp; &quot;table th{text-align:center;padding: 6px 4px 6px 4px;border: 1px solid black}&quot; &amp; vbNewLine
      str = str &amp; &quot;table td{text-align:center;border:1px solid black; padding: 2px 4px}&quot; &amp; vbNewLine
      'str = str &amp; &quot;table tr:nth-child(odd) td {background-color:red}&quot; &amp; vbNewLine
      str = str &amp; &quot;&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&quot;
               
      HeadHTMLTable = str
          
  End Function
  </code></pre>