margins of tables

R

Robin

aaargh!! please help. I have various tables with varying column thicknesses
but the same number of columns. I need to copy rows between tables. The
columns never line up and I am wasting so much time with trying to get them
aligned (dragging columns with ALT key down and/or playing with column
widths, etc). Is there a way of linking the position of the columns in one
row with the row above? Any tricks would be appreciated.
 
H

Helmut Weber

Hi Robin,

I don't see a way, but using a bit of programming, like:

Sub SameWidth()
' set all cells in row to width 0.5 inches
Dim oCll As Cell
Dim oRow As Row
Set oRow = selection.Rows(1)
For Each oCll In oRow.Cells
oCll.Width = InchesToPoints(0.5)
Next
MsgBox selection.Tables(1).Uniform
End Sub

As I don't know if you have any idea of VBA,
this is a very basic, very limited sample.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Robin

Super, thanks. This has just propelled me into the powerful world of Word
macros.
 
R

Robin

One more question: sometimes the "uniform" field comes back false, even
though all the columns have been set to be the same width. Any way of forcing
them to be uniform?
 
H

Helmut Weber

Hi Robin,

aaargh!!

Another bug? I very much think so.

First I messed a 5 times 5 table up, like this:

Sub Test9807()
Dim oCll As Cell
Dim oTbl As Table
Dim x As Single
Randomize
Set oTbl = ActiveDocument.Tables(1)
For Each oCll In oTbl.Range.Cells
oCll.Select
x = oCll.Width
x = x + Int((12 * Rnd) + 1)
oCll.Width = x
Next
End Sub

Then I tried to make it uniform, like this:

Sub Test9808()
Dim oCll As Cell
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
For Each oCll In oTbl.Range.Cells
oCll.Width = 30
Next
MsgBox oTbl.Uniform ' ok
End Sub

But I had no chance to get it to work with larger tables,
like 10 rows and 10 columns.
The more I tried, the less successful I was.

Maybe someone else knows better...
 
H

Helmut Weber

Hi Robin,

slighty better than looping through all cells,
which goes from left to right,
worked this alternative approach:

Sub Test9809()
Dim oCll As Cell
Dim oTbl As Table
Dim lRow As Long
Dim lClm As Long
Set oTbl = ActiveDocument.Tables(1)
For lClm = 1 To oTbl.Columns.Count
For lRow = 1 To oTbl.Rows.Count
oTbl.Cell(lRow, lClm).Select
Selection.Cells(1).Width = 30
Next
Next
MsgBox oTbl.Uniform
End Sub

This worked at first run for the rows 1 til 9
in a 10 times 10 table.
The second run then managed to set the width
of the cells in row 10, too.

HTH
 
H

Helmut Weber

Ha....

with Word _2003_ and a 10 times 20 table,
after the second run,
the table is uniform.
Sub Test9809()
Dim oCll As Cell
Dim oTbl As Table
Dim lRow As Long
Dim lClm As Long
Set oTbl = ActiveDocument.Tables(1)
For lClm = 1 To oTbl.Columns.Count
For lRow = 1 To oTbl.Rows.Count
oTbl.Cell(lRow, lClm).Select
Selection.Cells(1).Width = 30
Next
Next
MsgBox oTbl.Uniform
End Sub

Ja.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top