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

Re: Adjust column width in table by Jezebel

Jezebel
Wed Mar 29 22:05:14 CST 2006

If your table is non-uniform, it's probably simpler to forget about the
columns entirely. Just iterate the cells and set their widths directly.


Dim pCell as Word.Cell
Set pCell = tbl.cell(1,1)
Do
pCell.Width = rngExcel.Columns(pCell.ColumnIndex).ColumnWidth
set pCell = pCell.Next
Loop until pCell is nothing




"Alex St-Pierre" <AlexStPierre@discussions.microsoft.com> wrote in message
news:E222EBF4-0E79-4BB3-A321-B7A23E596578@microsoft.com...
> 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