Group:  Microsoft Word ยป microsoft.public.word.tables
Thread: margins of tables

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

margins of tables
Robin 05.07.2006 12:31:01
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.
Re: margins of tables
Helmut Weber <nbhymsjxdgcn[ at ]mailinator.com> 05.07.2006 15:07:50
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"


Re: margins of tables
Robin 06.07.2006 09:30:02
Super, thanks. This has just propelled me into the powerful world of Word
macros.

"Helmut Weber" wrote:

[Quoted Text]
> 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"
>
>
>
Re: margins of tables
Robin 06.07.2006 10:33:02
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?

"Robin" wrote:

[Quoted Text]
> Super, thanks. This has just propelled me into the powerful world of Word
> macros.
>
> "Helmut Weber" wrote:
>
> > 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"
> >
> >
> >
Re: margins of tables
Helmut Weber 06.07.2006 12:17:02
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...

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000 (german versions)



Re: margins of tables
Helmut Weber 06.07.2006 12:58:01
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

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000 (german versions)

Re: margins of tables
Helmut Weber <nbhymsjxdgcn[ at ]mailinator.com> 06.07.2006 14:54:07
Ha....

with Word _2003_ and a 10 times 20 table,
after the second run,
the table is uniform.

[Quoted Text]
>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"

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net