A
Alex St-Pierre
Hi,
I have a table (which contain some merged cells) and I would like to adjust
column width. For the first two rows, all works good but when I resized the
third row (which contains different column size), all the first 2 rows are
resized with the same value as row #3. What can I do ? I tried to use
SplitTable but is this the only way to adjust the column width of each row ?
Sub resize_table_row()
Dim rngExcel As Excel.Range
Dim tbl As Word.Table
Dim docWord1 As Word.Document
Set docWord1 = appWord.ActiveDocument
Set rngExcel = wbExcel.Application.sheets("table1.1").Range("table1_1")
Set rng = docWord1.Bookmarks("Table1_1").Range
Set tbl = rng.Tables(1)
With tbl.Rows
.LeftIndent = 0
End With
UsableWidth = 432
TableWidth = 0
For CellNo = 1 To rngExcel.Rows(1).Cells.Count
TableWidth = TableWidth + rngExcel.Columns(CellNo).ColumnWidth
Next CellNo
For i = 1 To tbl.Rows.Count
If i < tbl.Rows.Count Then
tbl.Rows(i + 1).Select
Selection.SplitTable
End If
For j = 1 To tbl.Rows(i).Cells.Count
tbl.Cell(i, j).Width = UsableWidth * rngExcel.Columns(j).ColumnWidth
/ TableWidth
Next j
If i < tbl.Rows.Count Then
tbl.cell(i,j).select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Next i--
End Sub
Thx!
Alex St-Pierre
I have a table (which contain some merged cells) and I would like to adjust
column width. For the first two rows, all works good but when I resized the
third row (which contains different column size), all the first 2 rows are
resized with the same value as row #3. What can I do ? I tried to use
SplitTable but is this the only way to adjust the column width of each row ?
Sub resize_table_row()
Dim rngExcel As Excel.Range
Dim tbl As Word.Table
Dim docWord1 As Word.Document
Set docWord1 = appWord.ActiveDocument
Set rngExcel = wbExcel.Application.sheets("table1.1").Range("table1_1")
Set rng = docWord1.Bookmarks("Table1_1").Range
Set tbl = rng.Tables(1)
With tbl.Rows
.LeftIndent = 0
End With
UsableWidth = 432
TableWidth = 0
For CellNo = 1 To rngExcel.Rows(1).Cells.Count
TableWidth = TableWidth + rngExcel.Columns(CellNo).ColumnWidth
Next CellNo
For i = 1 To tbl.Rows.Count
If i < tbl.Rows.Count Then
tbl.Rows(i + 1).Select
Selection.SplitTable
End If
For j = 1 To tbl.Rows(i).Cells.Count
tbl.Cell(i, j).Width = UsableWidth * rngExcel.Columns(j).ColumnWidth
/ TableWidth
Next j
If i < tbl.Rows.Count Then
tbl.cell(i,j).select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Next i--
End Sub
Thx!
Alex St-Pierre