title: OLE automation - WORD tabels (Delphi)
body: <p>I'm trying to make tables inside tables in WORD. of course in finall program it will be dinamical, which is not in this sample.</p>
  
  <p>Here is my sample code.</p>
  
  <pre><code> var
    aTable, bTable, cTable : OLEVariant;
  begin
    m_WordApplication := CreateOleObject('Word.Application') ;
    m_WordDocument := m_WordApplication.Documents.Add;
  
    aTable := m_WordDocument.Tables.Add(m_WordApplication.Selection.Range, 2, 1);
    aTable.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
    aTable.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
    aTable.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
    aTable.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
  
    bTable := m_WordDocument.Tables.Add(aTable.Cell(1, 1).Range, 2, 1);
    bTable.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
    bTable.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
    bTable.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
    bTable.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
  
    cTable := m_WordDocument.Tables.Add(aTable.Cell(2, 1).Range, 3, 1);
    cTable.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
    cTable.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
    cTable.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
    cTable.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
  
    m_WordDocument.SaveAs('C:/test.doc', False) ;
    m_WordApplication.Quit(False);
  </code></pre>
  
  <p>Firstly i put new table(2 rows, 1 column) on position of the cursor, and then i try to put second table in cell(1,1) and third in cell(2,1) of the first table. second table has also 2 rows and 1 column, but third table has 3 rows and 1 column. but instead of what i want i get second and third table whit only one row, regardless if i putt something in thier cell or not.i always see only the last string i put in that table.</p>
  
  <p>even more, if i put 1 row and 2 column table inside first table, than everything is normal.</p>
  
  <p>can you help me.</p>
  
  <p>thanks, Rok</p>