Adjust columns in a Word table using VBA
Posted on 2011-02-19
I am using VBA with Word 2010 and I want to adjust a seven-column table. I want to specify the widths of certain columns. Columns 1, 2 and 6 are hidden, so their width is of little importance, but I would like them to be as narrow as possible so that the visible columns have room to display things.
Column 3 contains nothing but a numbered list that Word generates to indicate a sequence number for each row. I need that to be just wide enough to display a three digit number that the computer generates.
Columns 4 and 5 should be as wide as possible.
Column 7 will contain a three-digit number, and I want it as narrow as possible so that columns 4 and 5 can be as wide as possible to display some text.
I am trying to control the size of certain columns with variants of this line of code that the macro recorder generated:
Selection.Tables(1).Columns(3).SetWidth ColumnWidth:=3, RulerStyle:=wdAdjustNone
As far as I can see, no matter what number I put after “ColumnWidth:=”, large or small, I get the same error message: “Run-time error; Value out of range”.
Can anyone help? To fill in the best values for the table, I would like to find out how wide the columns are when I adjust the table manually. However that is a different question, so I will save that for later.
Thanks for your help.
Priddis, Alberta, Canada