Hi,

I consider myself an experienced programmer in vba.. unfortunately that is in Access VBA which seems to be a hell of a lot easier than Word or Excel VBA.

Currently I am exporting data into a template built by code and shoved into Word. Initially I tried Words VBA (using record macro) but I was advised to use the proper objects (besides it killed the computer). Any how, I moved to html instead - easier. But it didn't like being transported back into word so I am having to try to do the templates in word objects.

The help file is practically useless as it keeps refering back to the selection object, which is used in the current doc and not via the code :/

I have the following code, which is in a loop.
VB Code:
  1. Set objWTable = Nothing
  2.                         Set objWTable = objWDoc.Tables.Add(objWRange, 5, 2)  'range,rows,cols
  3.                         objWTable.Cell(1, 1).Width = objWord.MillimetersToPoints(190) 'row,col (starts at 1)
  4.                         objWTable.Cell(1, 2).Width = objWord.MillimetersToPoints(10)  'row,col
  5.                         objWTable.Cell(1, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
  6.                         objWTable.Cell(1, 2).Height = objWord.MillimetersToPoints(20)   'row,col
  7.                         objWTable.Cell(2, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
  8.                         objWTable.Cell(2, 2).Width = objWord.MillimetersToPoints(120)  'row,col
  9.                         objWTable.Cell(2, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
  10.                         objWTable.Cell(2, 2).Height = objWord.MillimetersToPoints(82)   'row,col
  11.                         objWTable.Cell(3, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
  12.                         objWTable.Cell(3, 2).Width = objWord.MillimetersToPoints(120)  'row,col
  13.                         objWTable.Cell(3, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
  14.                         objWTable.Cell(3, 2).Height = objWord.MillimetersToPoints(82)   'row,col
  15.                         objWTable.Cell(4, 1).Width = objWord.MillimetersToPoints(80)    'row,col (starts at 1)
  16.                         objWTable.Cell(4, 2).Width = objWord.MillimetersToPoints(120)   'row,col
  17.                         objWTable.Cell(4, 1).Height = objWord.MillimetersToPoints(82)       'row,col (starts at 1)
  18.                         objWTable.Cell(4, 2).Height = objWord.MillimetersToPoints(82)       'row,col
  19.                         objWTable.Cell(5, 1).Width = objWord.MillimetersToPoints(100)       'row,col (starts at 1)
  20.                         objWTable.Cell(5, 2).Width = objWord.MillimetersToPoints(100)       'row,col
  21.                         objWTable.Cell(5, 1).Height = objWord.MillimetersToPoints(20)       'row,col (starts at 1)
  22.                         objWTable.Cell(5, 2).Height = objWord.MillimetersToPoints(20)       'row,col
  23.                        
  24.                         For lngX = 1 To 5
  25.                             For lngY = 1 To 2
  26.                                 objWTable.Cell(lngX, lngY).VerticalAlignment = 1 'center
  27.                                 objWTable.Cell(lngX, lngY).Range.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
  28.                             Next
  29.                         Next
  30.                         objWTable.Cell(1, 1).Range.ParagraphFormat.Alignment = 0
  31.                         objWTable.Cell(5, 1).Range.ParagraphFormat.Alignment = 0
  32.                         objWTable.Cell(5, 2).Range.ParagraphFormat.Alignment = 2
  33.                        
  34.                         objWTable.Rows.Alignment = 1 'wdAlignRowCenter
This creates my table and reorganises it to the correct widths etc.
First time its called, works fine.
However the second time its called it creates a new table BUT changes the sizes of the first table.

I was under the impression that:
VB Code:
  1. Set objWTable = objWDoc.Tables.Add(objWRange, 5, 2)  'range,rows,cols
Returned a table object, and I thoughtit returned the object just created - is this not the case?


Also I have used the same creation method but for a new table in a cell. This created a table of one row and how ever many columns, even if you specify more than one row. Is this a bug?

Vince