title: (MATLAB) ActiveX -> VBA -> quickest way of filling up / rowwise coloring a MS Word table?
body: <p>What is the quickest way of creating, filling up and coloring rowwise a MS Word table over ActiveX -> VBA (In my particular case, Im doing it over MATLAB) ?</p>
  
  <p>Right now I'm using it in the following way </p>
  
  <pre><code>hdlActiveX = actxserver('Word.Application');
  ...
  hdlActiveX.ActiveDocument.Tables.Add(hdlActiveX.Selection.Range, nbRows, nbCols, 1, 1).Rows.Alignment = 1;
  ...
  % create dataCell{nbRows, nbCols}  containing the table values row- and columnwise
  ...
  nrTable = ... % an integer selecting a table in the MS Word document 
  ...
  for r = 1:nbRows
     for c = 1:nbCols
         % Write data into current cell
        hdlActiveX.ActiveDocument.Tables.Item(1).Cell(r,c).Range.Text = dataCell{r, c};
  
        % setting a different background color rowwise, if a condtion is met
        % this is even bigger performance reducer
        if condition
            for iCol = 1:nbCols
                hdlActiveX.ActiveDocument.Tables.Item(nrTable).Cell(r,iCol).Select;
                hdlActiveX.Selection.Shading.BackgroundPatternColor = color;
            end
        end
  
     end
  end
  </code></pre>
  
  <p>but it takes ages, really, really long to fill up, and especially to color rowwise the MS Word (ActiveX) table ... So how the performance of filling up the table could  be improved ?</p>
  
  <p>Thanks in advance,</p>