Ecniv
May 5th, 2003, 02:50 AM
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.
Set objWTable = Nothing
Set objWTable = objWDoc.Tables.Add(objWRange, 5, 2) 'range,rows,cols
objWTable.Cell(1, 1).Width = objWord.MillimetersToPoints(190) 'row,col (starts at 1)
objWTable.Cell(1, 2).Width = objWord.MillimetersToPoints(10) 'row,col
objWTable.Cell(1, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
objWTable.Cell(1, 2).Height = objWord.MillimetersToPoints(20) 'row,col
objWTable.Cell(2, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(2, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(2, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(2, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(3, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(3, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(3, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(3, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(4, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(4, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(4, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(4, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(5, 1).Width = objWord.MillimetersToPoints(100) 'row,col (starts at 1)
objWTable.Cell(5, 2).Width = objWord.MillimetersToPoints(100) 'row,col
objWTable.Cell(5, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
objWTable.Cell(5, 2).Height = objWord.MillimetersToPoints(20) 'row,col
For lngX = 1 To 5
For lngY = 1 To 2
objWTable.Cell(lngX, lngY).VerticalAlignment = 1 'center
objWTable.Cell(lngX, lngY).Range.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
Next
Next
objWTable.Cell(1, 1).Range.ParagraphFormat.Alignment = 0
objWTable.Cell(5, 1).Range.ParagraphFormat.Alignment = 0
objWTable.Cell(5, 2).Range.ParagraphFormat.Alignment = 2
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:
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
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.
Set objWTable = Nothing
Set objWTable = objWDoc.Tables.Add(objWRange, 5, 2) 'range,rows,cols
objWTable.Cell(1, 1).Width = objWord.MillimetersToPoints(190) 'row,col (starts at 1)
objWTable.Cell(1, 2).Width = objWord.MillimetersToPoints(10) 'row,col
objWTable.Cell(1, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
objWTable.Cell(1, 2).Height = objWord.MillimetersToPoints(20) 'row,col
objWTable.Cell(2, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(2, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(2, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(2, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(3, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(3, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(3, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(3, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(4, 1).Width = objWord.MillimetersToPoints(80) 'row,col (starts at 1)
objWTable.Cell(4, 2).Width = objWord.MillimetersToPoints(120) 'row,col
objWTable.Cell(4, 1).Height = objWord.MillimetersToPoints(82) 'row,col (starts at 1)
objWTable.Cell(4, 2).Height = objWord.MillimetersToPoints(82) 'row,col
objWTable.Cell(5, 1).Width = objWord.MillimetersToPoints(100) 'row,col (starts at 1)
objWTable.Cell(5, 2).Width = objWord.MillimetersToPoints(100) 'row,col
objWTable.Cell(5, 1).Height = objWord.MillimetersToPoints(20) 'row,col (starts at 1)
objWTable.Cell(5, 2).Height = objWord.MillimetersToPoints(20) 'row,col
For lngX = 1 To 5
For lngY = 1 To 2
objWTable.Cell(lngX, lngY).VerticalAlignment = 1 'center
objWTable.Cell(lngX, lngY).Range.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
Next
Next
objWTable.Cell(1, 1).Range.ParagraphFormat.Alignment = 0
objWTable.Cell(5, 1).Range.ParagraphFormat.Alignment = 0
objWTable.Cell(5, 2).Range.ParagraphFormat.Alignment = 2
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:
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