set the width of specific columns in a table

User avatar
stuck
Panoramic Lounger
Posts: 8240
Joined: 25 Jan 2010, 09:09
Location: retirement

set the width of specific columns in a table

Post by stuck »

This ought to be simple but it eludes me...

Al I want to do is set the first column of my table to be 2cm and the second column to be 0.2cm but none of the code I've tried has worked. So what am I doing wrong? All of these fail with 'argument not optional'

Code: Select all

ActiveDocument.Tables(1).Columns(1).SetWidth ColumnWidth:45
ActiveDocument.Tables(1).Columns(2).SetWidth ColumnWidth:=6
ActiveDocument.Tables(1).Columns(1).SetWidth (ColumnWidth = 45)
ActiveDocument.Tables(1).Columns(2).SetWidth (ColumnWidth = 6)
:scratch:

Ken

User avatar
StuartR
Administrator
Posts: 12662
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: set the width of specific columns in a table

Post by StuartR »

ActiveDocument.Tables(1).Columns(1).Width = CentimetersToPoints(2.0)
works for me
ActiveDocument.Tables(1).Columns(1).Width = CentimetersToPoints(0.2)
only worked after I changed the default cell padding so that it was less than 0.2 centimeters.
StuartR


User avatar
stuck
Panoramic Lounger
Posts: 8240
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: set the width of specific columns in a table

Post by stuck »

Thanks Stuart, I've also made some progress and:

Code: Select all

Selection.Columns(1).Width = CentimetersToPoints(2)
Selection.Columns(2).Width = CentimetersToPoints(0.42)
seems to be close to what I want. I've already set the internal cell margins to zero but I must have something earlier in the code that's setting the preferred cell width to 0.42 so that's as narrow as I can make col. two at the moment. Fresh eyes tomorrow ought to allow me to get things in the right order.

Ken

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: set the width of specific columns in a table

Post by macropod »

If you don't first set:
.PreferredWidthType = wdPreferredWidthPoints
Word won't know that you don't mean:
.PreferredWidthType =wdPreferredWidthPercent
or:
.PreferredWidthType = wdPreferredWidthAuto
Paul Edstein
[Fmr MS MVP - Word]

User avatar
stuck
Panoramic Lounger
Posts: 8240
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: set the width of specific columns in a table

Post by stuck »

macropod wrote:.PreferredWidthType = wdPreferredWidthAuto
:cheers: That seemed to be the bit of magic I was missing.
:thankyou:

Ken